How to run python unittest inside PyCharm with buffer=True - python

Building on top of How to assert output with nosetest/unittest in python? I would like to acieve this inside Pyharm. However, pycharm does not run:
$ python -m tests.test_mymodule --buffer
Rather it does:
$ /usr/bin/python2.7 /opt/helpers/pycharm/utrunner.py \
/home/oz123/PycharmProjects/account/tests/test_mymodule.py true
So, I ran it with:
$ /usr/bin/python2.7 /opt/helpers/pycharm/utrunner.py \
/home/oz123/PycharmProjects/account/tests/test_mymodule.py --buffer true
And it crashes with:
##teamcity[testFinished duration='72' name='test_1_list_files']
Traceback (most recent call last):
File "/opt/helpers/pycharm/utrunner.py", line 151, in <module>
TeamcityTestRunner().run(all, **options)
File "/opt/helpers/pycharm/tcunittest.py", line 249, in run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
test(result)
File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
test(result)
File "/usr/lib/python2.7/unittest/case.py", line 396, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/case.py", line 356, in run
result.addError(self, sys.exc_info())
File "/opt/helpers/pycharm/tcunittest.py", line 108, in addError
TestResult.addError(self, test, err)
File "/usr/lib/python2.7/unittest/result.py", line 19, in inner
return method(self, *args, **kw)
File "/usr/lib/python2.7/unittest/result.py", line 116, in addError
self.errors.append((test, self._exc_info_to_string(err, test)))
File "/usr/lib/python2.7/unittest/result.py", line 167, in _exc_info_to_string
output = sys.stdout.getvalue()
AttributeError: 'file' object has no attribute 'getvalue'
Does any one know where does pycharm store the output? How can I access it?

Related

Error while running portia on docker in ubuntu

I am getting following error while running portia on docker in ubuntu 14.04. I have gone through following answers, but they are not working.
Autobahn websocket issue while running with twistd using tac file
docker command: sudo docker run --rm -p 9001:9001 --name portia portia
Docker version 1.9.1, build a34a1d5
Twisted: 15.5.0
python - 2.7
building portia image downloaded from https://github.com/scrapinghub/portia
2015-12-12 15:34:03.676329 [HTTPChannel,56,127.0.0.1] Unhandled Error
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/basic.py", line 571, in dataReceived
why = self.lineReceived(line)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 1676, in lineReceived
self.allContentReceived()
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 1755, in allContentReceived
req.requestReceived(command, path, version)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 823, in requestReceived
self.process()
--- <exception caught here> ---
File "/usr/local/lib/python2.7/dist-packages/twisted/web/server.py", line 189, in process
self.render(resrc)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/server.py", line 238, in render
body = resrc.render(self)
File "/app/slyd/slyd/splash/ferry.py", line 79, in render
return WebSocketResource.render(self, request)
File "/usr/local/lib/python2.7/dist-packages/autobahn/twisted/resource.py", line 162, in render
protocol.makeConnection(transport)
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/protocol.py", line 487, in makeConnection
self.connectionMade()
File "/usr/local/lib/python2.7/dist-packages/autobahn/twisted/websocket.py", line 88, in connectionMade
self._connectionMade()
File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 2720, in _connectionMade
WebSocketProtocol._connectionMade(self)
File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 1187, in _connectionMade
self.openHandshakeTimeoutCall = txaio.call_later(self.openHandshakeTimeout, self.onOpenHandshakeTimeout)
File "/usr/local/lib/python2.7/dist-packages/txaio/_unframework.py", line 43, in _throw_usage_error
"To use txaio, you must first select a framework "
exceptions.RuntimeError: To use txaio, you must first select a framework with .use_twisted() or .use_txaio()
2015-12-12 15:34:03.684892 [HTTPChannel,56,127.0.0.1] Unhandled Error
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/twisted/python/log.py", line 101, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/usr/local/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "/usr/local/lib/python2.7/dist-packages/qtreactor/qt4base.py", line 100, in _read
data = w.doRead()
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 209, in doRead
return self._dataReceived(data)
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 215, in _dataReceived
rval = self.protocol.dataReceived(data)
File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/basic.py", line 571, in dataReceived
why = self.lineReceived(line)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 1676, in lineReceived
self.allContentReceived()
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 1755, in allContentReceived
req.requestReceived(command, path, version)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 823, in requestReceived
self.process()
File "/usr/local/lib/python2.7/dist-packages/twisted/web/server.py", line 191, in process
self.processingFailed(failure.Failure())
File "/app/slyd/slyd/server.py", line 30, in processingFailed
return WebRequest.processingFailed(self, reason)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/server.py", line 329, in processingFailed
self.write(body)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/server.py", line 217, in write
http.Request.write(self, data)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 1006, in write
self.transport.writeSequence(l)
exceptions.AttributeError: 'NoneType' object has no attribute 'writeSequence'
2015-12-12 15:34:03.685464 [HTTPChannel,56,127.0.0.1] Unhandled Error
Traceback (most recent call last):
File "bin/slyd", line 41, in <module>
splash.server.main()
File "/usr/local/lib/python2.7/dist-packages/splash/server.py", line 386, in main
reactor.run()
File "/usr/local/lib/python2.7/dist-packages/qtreactor/qt4base.py", line 282, in run
self._blockApp.exec_()
File "/usr/local/lib/python2.7/dist-packages/qtreactor/qt4base.py", line 110, in read
log.callWithLogger(w, _read)
--- <exception caught here> ---
File "/usr/local/lib/python2.7/dist-packages/twisted/python/log.py", line 101, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/usr/local/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
return func(*args,**kw)
File "/usr/local/lib/python2.7/dist-packages/qtreactor/qt4base.py", line 107, in _read
self.qt_reactor._disconnectSelectable(w, sys.exc_info()[1], False)
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 260, in _disconnectSelectable
selectable.connectionLost(failure.Failure(why))
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 293, in connectionLost
protocol.connectionLost(reason)
File "/usr/local/lib/python2.7/dist-packages/autobahn/twisted/websocket.py", line 98, in connectionLost
self._connectionLost(reason)
File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 2732, in _connectionLost
WebSocketProtocol._connectionLost(self, reason)
File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 1209, in _connectionLost
if self.autoPingPendingCall:
exceptions.AttributeError: 'FerryServerProtocol' object has no attribute 'autoPingPendingCall'
`

Why does pyramid give exception of zipimporter.get_filename()

I am writing a simple pyramid application, and I try to run it pserve development.ini.
I got this:
Traceback (most recent call last):
File "/apps/my/python/packages/.mytest/current/bin/pserve", line 5, in <module>
sys.exit(pyramid.scripts.pserve.main())
File "/users/is/pypi/egg_cache/p/pyramid-1.5.1-py2.7.egg/pyramid/scripts/pserve.py", line 51, in main
return command.run()
File "/users/is/pypi/egg_cache/p/pyramid-1.5.1-py2.7.egg/pyramid/scripts/pserve.py", line 316, in run
global_conf=vars)
File "/users/is/pypi/egg_cache/p/pyramid-1.5.1-py2.7.egg/pyramid/scripts/pserve.py", line 340, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/util.py", line 58, in fix_call
reraise(*exc_info)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/compat.py", line 23, in reraise
exec('raise t, e, tb', dict(t=t, e=e, tb=tb))
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/util.py", line 55, in fix_call
val = callable(*args, **kw)
File "/users/is/pypi/egg_cache/at/mytest-1.9.0-py2.7.egg//mytest/__init__.py", line 108, in main
File "/users/is/pypi/egg_cache/p/pyramid-1.5.1-py2.7.egg/pyramid/config/__init__.py", line 930, in scan
ignore=ignore)
File "/users/is/pypi/egg_cache/v/venusian-1.0a7-py2.7.egg/venusian/__init__.py", line 187, in scan
fn = loader.get_filename()
TypeError: zipimporter.get_filename() takes exactly 1 argument (0 given)
anyone could tell me how it comes?
Ok. I choose not to delete this question as I believe it might help other people who have the same problems.
Basically venusian does not support zipped egg. So when you produce your egg for pyramid, do not do it as zip egg.

Scrapy errors when using -t csv -o data.csv

I have my scrapy bot running on two different systems. One of them is working properly while the other one isn't. They're identical copies. When I use -t csv -o data.csv, I get the following traceback.
Traceback (most recent call last):
File "/home/scraper/.python/bin/scrapy", line 4, in <module>
execute()
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/cmdline.py", line 143, in execute
_run_print_help(parser, _run_command, cmd, args, opts)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/cmdline.py", line 89, in _run_print_help
func(*a, **kw)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/cmdline.py", line 150, in _run_command
cmd.run(args, opts)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/commands/crawl.py", line 50, in run
self.crawler_process.start()
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/crawler.py", line 92, in start
if self.start_crawling():
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/crawler.py", line 124, in start_crawling
return self._start_crawler() is not None
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/crawler.py", line 139, in _start_crawler
crawler.configure()
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/crawler.py", line 46, in configure
self.extensions = ExtensionManager.from_crawler(self)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/middleware.py", line 50, in from_crawler
return cls.from_settings(crawler.settings, crawler)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/middleware.py", line 31, in from_settings
mw = mwcls.from_crawler(crawler)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/contrib/feedexport.py", line 162, in from_crawler
o = cls(crawler.settings)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/contrib/feedexport.py", line 144, in __init__
if not self._storage_supported(self.urifmt):
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/contrib/feedexport.py", line 214, in _storage_supported
self._get_storage(uri)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/contrib/feedexport.py", line 225, in _get_storage
return self.storages[urlparse(uri).scheme](uri)
File "/home/scraper/.python/lib/python2.7/site-packages/scrapy/contrib/feedexport.py", line 70, in __init__
self.path = file_uri_to_path(uri)
File "/home/scraper/.python/lib/python2.7/site-packages/w3lib/url.py", line 141, in file_uri_to_path
uri_path = moves.urllib.parse.urlparse(uri).path
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'
Looks like your six module is not the required by w3lib.
Try:
pip install -U w3lib six

Nose Test Error

I am using the command
nosetests -v --with-coverage --cover-package=task --cover-erase --cover-html-dir=cover --cover-html --with-xunit task
to run the test cases
but in the end after running all the testcases I get the nosetests.xml blank and the following error.
Traceback (most recent call last):
File "/home/nishant-un/env/bin/nosetests", line 9, in <module>
load_entry_point('nose==1.0.0', 'console_scripts', 'nosetests')()
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/core.py", line 118, in __init__
**extra_args)
File "/usr/lib/python2.7/unittest/main.py", line 95, in __init__
self.runTests()
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/core.py", line 197, in runTests
result = self.testRunner.run(self.test)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/core.py", line 61, in run
test(result)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 176, in __call__
return self.run(*arg, **kw)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 223, in run
test(orig)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 176, in __call__
return self.run(*arg, **kw)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 223, in run
test(orig)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 176, in __call__
return self.run(*arg, **kw)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 223, in run
test(orig)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 176, in __call__
return self.run(*arg, **kw)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 223, in run
test(orig)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 176, in __call__
return self.run(*arg, **kw)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 223, in run
test(orig)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 176, in __call__
return self.run(*arg, **kw)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/suite.py", line 223, in run
test(orig)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/case.py", line 45, in __call__
return self.run(*arg, **kwarg)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/case.py", line 138, in run
result.addError(self, err)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/proxy.py", line 118, in addError
formatted = plugins.formatError(self.test, err)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/plugins/manager.py", line 94, in __call__
return self.call(*arg, **kw)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/plugins/manager.py", line 136, in chain
result = meth(*arg, **kw)
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/plugins/logcapture.py", line 223, in formatError
test.capturedLogging = records = self.formatLogRecords()
File "/home/nishant-un/env/local/lib/python2.7/site-packages/nose/plugins/logcapture.py", line 231, in formatLogRecords
return [safe_str(format(r)) for r in self.handler.buffer]
File "/usr/lib/python2.7/logging/__init__.py", line 723, in format
return fmt.format(record)
File "/usr/lib/python2.7/logging/__init__.py", line 464, in format
record.message = record.getMessage()
File "/usr/lib/python2.7/logging/__init__.py", line 328, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
I have tried almost everything that i found in google. Even deleted .coverage file and all .pyc but it still shows the same error.Any Idea..?
This TypeError is because of mixing different formats.
Your error is inside formatLogRecords()
Instead of:
msg = msg % self.args
You should use format():
myMsg = "{} {} {} {} {}".format(param1, param2, param3, param4)
And even much better approach will be:
args = ['1', '2', '3', '4']
myMsg = (' '.join('{}'.format(k) for k in args))
Result:
>>> 1 2 3 4
That way your args can be with a flexible.
One thing to try is to run nose with no log capturing --nologcapture. Most likely you have a rogue logging somewhere at the import level, and it chokes nose before tests can run.
You can usually expose those bugs easily if you just run python task.py on your test files - the error will get thrown immediately.
If this still does not solve your problem, try running nose within python using nose.run() within your test __main__ function, and fire it off with python -m pdb task.py it will let you debug such errors, even if --pdb option in nose does not work.

Launching nose with --with-gae option raises ValueError for missing lib/ipaddr

Setting up the testing framework and I can't seem to get past this error:
Traceback (most recent call last):
File "/usr/local/bin/nosetests", line 8, in <module>
load_entry_point('nose==1.1.2', 'console_scripts', 'nosetests')()
File "/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg/nose/core.py", line 118, in __init__
**extra_args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg/nose/core.py", line 135, in parseArgs
self.config.configure(argv, doc=self.usage())
File "/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg/nose/config.py", line 338, in configure
self.plugins.configure(options, self)
File "/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg/nose/plugins/manager.py", line 271, in configure
cfg(options, config)
File "/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg/nose/plugins/manager.py", line 94, in __call__
return self.call(*arg, **kw)
File "/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg/nose/plugins/manager.py", line 162, in simple
result = meth(*arg, **kw)
File "build/bdist.macosx-10.7-intel/egg/nosegae.py", line 80, in configure
File "/usr/local/bin/dev_appserver.py", line 76, in <module>
DIR_PATH = get_dir_path(os.path.join('lib', 'ipaddr'))
File "/usr/local/bin/dev_appserver.py", line 66, in get_dir_path
'file and %s.' % sibling)
ValueError: Could not determine directory that contains both, this file and lib/ipaddr.
It's a correct error coming from dev_appserver.py... there is no lib/ipaddr in the /usr/local/bin directory.
Why is nosetests triggering the raising of this error? Why does dev_appengine try to look for lib/ipaddr in the first place?

Categories