Search code examples
python-2.7bddpytest

Can't use pytest-bdd after installation


I installed pytest-bdd at /home/marlu/.local using python setup.py install --user, since I don't have admin privileges. Both python2.7 and pytest are located at /usr/bin/. When I check if pytest-bdd is working correctly by running py.test --version I get an error, could anyone tell me why? Thanks!

Error output:

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'

Solution

  • @pytest.hookspec was introduced in pytest 2.8, so you'd need to upgrade pytest, or downgrade pytest-bdd to 2.16.1. (Whoops, I was the one who broke 2.7 compatibility)