安装后无法使用pytest-bdd

Can't use pytest-bdd after installation

我使用 python setup.py install --user/home/marlu/.local 安装了 pytest-bdd,因为我没有管理员权限。 python2.7 和 pytest 都位于 /usr/bin/。当我通过 运行 py.test --version 检查 pytest-bdd 是否正常工作时出现错误,谁能告诉我为什么?谢谢!

错误输出:

Traceback (most recent call last):
  File "/usr/bin/py.test", line 9, in <module>
    load_entry_point('pytest==2.7.0', 'console_scripts', 'py.test-2.7')()
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 32, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 85, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
    return self._docall(self.methods, kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
    firstresult=self.firstresult).execute()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 393, in execute
    return wrapped_call(method(*args), self.execute)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 109, in wrapped_call
    wrap_controller.send(call_outcome)
  File "/usr/lib/python2.7/site-packages/_pytest/helpconfig.py", line 28, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 138, in get_result
    py.builtin._reraise(*ex)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 123, in __init__
    self.result = func()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
    res = method(*args)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 636, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 746, in parse
    self._preparse(args)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 713, in _preparse
    self.pluginmanager.consider_setuptools_entrypoints()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 282, in consider_setuptools_entrypoints
    self.register(plugin, name=name)
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 189, in register
    reg(plugin, name)  # may call addhooks
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 604, in _register_plugin
    {'pluginmanager': self.pluginmanager})
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 360, in call_plugin
    kwargs=kwargs, firstresult=True).execute()
  File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
    res = method(*args)
  File "/home/marlu/.local/lib/python2.7/site-packages/pytest_bdd-2.17.0-py2.7.egg/pytest_bdd/plugin.py", line 15, in pytest_addhooks
    from pytest_bdd import hooks
  File "/home/marlu/.local/lib/python2.7/site-packages/pytest_bdd-2.17.0-py2.7.egg/pytest_bdd/hooks.py", line 38, in <module>
    @pytest.hookspec(firstresult=True)
AttributeError: 'module' object has no attribute 'hookspec'

@pytest.hookspec 是在 pytest 2.8 中引入的,因此您需要升级 pytest,或将 pytest-bdd 降级到 2.16.1。 (糟糕,我是那个破坏了 2.7 兼容性的人)