4

update the question and subject as I discovered more. Without conftest.py "pytest --help" returns help content. With the conftest.py "pytest --help" returns this

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'

my 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')

The conftest.py hasn't been updated for two months but I have a new laptop. Mac High Sierra.

Python 3.6.6 . or 3.7.0
pytest version 3.7.1, or 3.7.0
Soprano86
  • 73
  • 2
  • 10
  • Your `pytest_configure` hook impl misses the `config` argument. – hoefling Aug 03 '18 at 08:30
  • https://docs.pytest.org/en/latest/reference.html#_pytest.config.PytestPluginManager.pytest_configure – phd Aug 03 '18 at 16:18
  • (Thank you) I realize I do have pytest_configure(config) in conftest.py. I updated the post included conftest. I don't know why pytest say it is missing. – Soprano86 Aug 03 '18 at 17:18

1 Answers1

9

Hooks are no fixtures, they are plain functions that pytest will find using their exact signatures. So, to fix your issue, just remove pytest.fixture decorator from the hook and you're good to go:

def pytest_configure(config):
    import env
    if config.getoption('--user'):
        env.user_name = config.getoption('--user')
hoefling
  • 59,418
  • 12
  • 147
  • 194
  • Thank you for pointing out. I don't remember why I put a fixture there. I will try to remove it and see if it works. I also found my path messed up. Pytest was calling Python2 even though I was in Python2 virtualenv. Tests are running after fixing that. Will update after I try. – Soprano86 Aug 10 '18 at 19:50
  • 1
    Glad I could help! If the question is answered, you can upvote the answer and accept it to mark the question resolved. – hoefling Aug 11 '18 at 20:36
  • I finally got chance to verify @hoefling 's approach. It works! My co-worker also tried and it worked for him. Unfortunately my stack overflow reputation is not high enough to make the upvote shown. When I get enough of that I will come back vote again. Thanks again. – Soprano86 Aug 17 '18 at 22:57