Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using nosetests in PyCharm having python 2 and 3 installed side by side

I am trying to use nosetest with python 2 and 3 isntalled side by side in PyCharm (2.7.3).

Everything works fine under python 2.7, but any test in python 3.4 fails with the following error:

Traceback (most recent call last):
  File "/home/robert/Programme/pycharm-2.7.3/helpers/pycharm/noserunner.py", line 91, in <module>
    process_args()
  File "/home/robert/Programme/pycharm-2.7.3/helpers/pycharm/noserunner.py", line 88, in process_args
    TestProgram(argv=argv, config=config)
  File "/usr/local/lib/python3.4/dist-packages/nose/core.py", line 121, in __init__
    **extra_args)
  File "/usr/lib/python3.4/unittest/main.py", line 93, in __init__
    self.runTests()
  File "/usr/local/lib/python3.4/dist-packages/nose/core.py", line 207, in runTests
    result = self.testRunner.run(self.test)
  File "/usr/local/lib/python3.4/dist-packages/nose/core.py", line 62, in run
    test(result)
  File "/usr/local/lib/python3.4/dist-packages/nose/suite.py", line 177, in __call__
    return self.run(*arg, **kw)
  File "/usr/local/lib/python3.4/dist-packages/nose/suite.py", line 224, in run
    test(orig)
  File "/usr/local/lib/python3.4/dist-packages/nose/suite.py", line 177, in __call__
    return self.run(*arg, **kw)
  File "/usr/local/lib/python3.4/dist-packages/nose/suite.py", line 224, in run
    test(orig)
  File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 46, in __call__
    return self.run(*arg, **kwarg)
  File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 139, in run
    result.addError(self, err)
  File "/usr/local/lib/python3.4/dist-packages/nose/proxy.py", line 131, in addError
    plugins.addError(self.test, err)
  File "/usr/local/lib/python3.4/dist-packages/nose/plugins/manager.py", line 99, in __call__
    return self.call(*arg, **kw)
  File "/usr/local/lib/python3.4/dist-packages/nose/plugins/manager.py", line 167, in simple
    result = meth(*arg, **kw)
  File "/home/robert/Programme/pycharm-2.7.3/helpers/pycharm/nose_utils.py", line 51, in addError
    err = self.formatErr(err)
  File "/home/robert/Programme/pycharm-2.7.3/helpers/pycharm/nose_utils.py", line 58, in formatErr
    return ''.join(traceback.format_exception(exctype, value, tb))
  File "/usr/lib/python3.4/traceback.py", line 181, in format_exception
    return list(_format_exception_iter(etype, value, tb, limit, chain))
  File "/usr/lib/python3.4/traceback.py", line 146, in _format_exception_iter
    for value, tb in values:
  File "/usr/lib/python3.4/traceback.py", line 125, in _iter_chain
    context = exc.__context__
AttributeError: 'str' object has no attribute '__context__'

Moreover in the run configuration of the nosetest run for the python 3 interpreter it says:

WARNING: No nosetest runner found in selected interpreter

What do I have to do in order to fix this? How do I choose an appropriate runner for python 3 nosetests in pyCharm (2.7.3) ? Thanks!

EDIT: Btw, it's pyCharm 2.7.3

like image 298
SmCaterpillar Avatar asked Jul 26 '14 13:07

SmCaterpillar


1 Answers

Ok, to post my workaround here to make it easier to find for others. Replacing line 58 in PathToPyCharm/pycharm-2.7.3/helpers/pycharm/nose_utils.py with

if sys.version_info[0]==3:
    return ''.join(traceback.format_exception(exctype, value, tb, chain=False))
else:
    return ''.join(traceback.format_exception(exctype, value, tb))

made nosetests work with python 3.4 and 2.7. Yet, using python 3.4 the entire stack-trace is lost if an error occurs. As a consequence, debugging becomes a nightmare :(

Finally, I solved the problem simply by upgrading my PyCharm version to 3.4.1.

like image 169
SmCaterpillar Avatar answered Sep 28 '22 01:09

SmCaterpillar