8

我有一个非常简单的测试脚本只是为了学习pytest,tmp.py:

def square(x):
    return x*x
def test_square():
    assert square(4) == 16

使用 Pycharm 运行此脚本,我已经配置了我的项目设置,以便将 pytest 用作我的默认测试运行器。当我运行上面的代码时,我收到以下错误:

/Users/mingxiao/webdav_2.7.5/bin/python /Applications/PyCharm.app/helpers/pycharm/pytestrunner.py -p pytest_teamcity /Users/mingxiao/dev/juggernaut/src/integrations/webDAV/demo/tmp.py "-k test_square"
Testing started at 4:41 PM ...
Traceback (most recent call last):
  File "/Applications/PyCharm.app/helpers/pycharm/pytestrunner.py", line 51, in <module>
    main()
  File "/Applications/PyCharm.app/helpers/pycharm/pytestrunner.py", line 20, in main
    _pluginmanager = PluginManager(load=True)
TypeError: __init__() got an unexpected keyword argument 'load'

Process finished with exit code 1

我正在运行 PyCharm 3.0 专业版、pytest 2.4.2 和 python 2.7.5。似乎是它的 PyCharm 本身导致了这个问题。

4

4 回答 4

11

It appears to be an incompatibility between PyCharm and py.test 2.4.x. If you install py.test 2.3.5 (for example, pip install pytest==2.3.5) it works fine. I suggest submitting a bug report to JetBrains.

于 2013-10-08T12:38:46.733 回答
2

PyCharm pytest 助手似乎与较新的 pytest 不兼容。在他们修复它之前,用 py.test 脚本的内容替换它就可以了。

Helper 位于PyCharm.app/helpers/pycharm/pytestrunner.py(您可以在尝试运行测试时看到此路径)。把它的输出放进cat `which py.test`去,对我来说是:

  __requires__ = 'pytest==2.5.1'
  import sys
  from pkg_resources import load_entry_point

  if __name__ == '__main__':
      sys.exit(
          load_entry_point('pytest==2.5.1', 'console_scripts', 'py.test')()
      )
于 2014-01-23T11:51:32.850 回答
1

似乎问题是在 pycharm 跟踪器http://youtrack.jetbrains.com/issue/PY-11235

于 2014-01-12T11:24:20.897 回答
0

在 PyCharm 中将 pytest 添加到您的项目中:设置 --> 项目解释器 --> 点击加号绿色图标 --> 搜索“pytests” --> 点击“安装包”按钮

重新运行,现在应该可以了

于 2017-04-26T14:25:10.853 回答