在PyCharm中使用nosetests,python 2和3并排安装

时间:2014-07-26 13:51:57

标签: python-2.7 python-3.x pycharm nose nosetests

我试图在PyCharm(2.7.3)中使用与python 2和3并排的鼻子测试。

在python 2.7下一切正常,但是python 3.4中的任何测试都会失败并出现以下错误:

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__'

此外,在python 3解释器的运行配置中,它说:

WARNING: No nosetest runner found in selected interpreter

为了解决这个问题,我该怎么办?如何在pyCharm(2.7.3)中为python 3 nosetests选择合适的运行器?谢谢!

编辑:顺便说一句,这是pyCharm 2.7.3

1 个答案:

答案 0 :(得分:7)

好的,在这里发布我的解决方法,以便更容易找到其他人。用{/ 1>替换PathToPyCharm/pycharm-2.7.3/helpers/pycharm/nose_utils.py中的第58行

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))

使nosetests与python 3.4和2.7一起工作。然而,使用python 3.4,如果发生错误,整个堆栈跟踪将丢失。结果,调试变成了一场噩梦:(

最后,我只是将PyCharm版本升级到3.4.1来解决问题。