gpt4 book ai didi

python-2.7 - 在 PyCharm 中使用并排安装了 python 2 和 3 的 Nose 测试

转载 作者:行者123 更新时间:2023-12-04 11:51:52 24 4
gpt4 key购买 nike

我正在尝试在 PyCharm (2.7.3) 中并排使用与 python 2 和 3 并排安装的 Nose 测试。

在 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解释器的nosetest运行的运行配置中,它说:
WARNING: No nosetest runner found in selected interpreter

我该怎么做才能解决这个问题?如何在 pyCharm (2.7.3) 中为 python 3 Nose 测试选择合适的运行者?谢谢!

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

最佳答案

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

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 解决了这个问题。

关于python-2.7 - 在 PyCharm 中使用并排安装了 python 2 和 3 的 Nose 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24971709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com