繁体   English   中英

在conftest.py中使用pytest_configure()时pytest --help无法运行

[英]pytest --help does not run when using pytest_configure() in conftest.py

随着我发现更多内容,更新问题和主题。 没有conftest.py,“ pytest --help”将返回帮助内容。 与conftest.py“ pytest --help”返回此

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/_pytest/main.py", line 174, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 588, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/pluggy/hooks.py", line 280, in call_historic
INTERNALERROR>     res = self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/user/git/py3env/lib/python3.6/site-packages/_pytest/fixtures.py", line 980, in result
INTERNALERROR>     return function(*args, **kwargs)
INTERNALERROR> TypeError: pytest_configure() missing 1 required positional argument: 'config'

我的conftest.py

def pytest_addoption(parser):
    parser.addoption("--user", action="store", default="admin", help="user name")
    parser.addoption("--password", action="store", default="password", help="user password")

@pytest.fixture(scope='module')
def pytest_configure(config):
      import env
      if config.getoption('--user'):
          env.user_name = config.getoption('--user')

conftest.py已经两个月没有更新了,但是我有一台新笔记本电脑。 Mac High Sierra。

Python 3.6.6 . or 3.7.0
pytest version 3.7.1, or 3.7.0

钩子不是固定装置,它们是pytest使用其精确签名可以找到的简单函数。 因此,要解决您的问题,只需从钩子中删除pytest.fixture装饰器,就可以了:

def pytest_configure(config):
    import env
    if config.getoption('--user'):
        env.user_name = config.getoption('--user')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM