pytest: pytest 5.0.1 cannot start with Python 3.5.2

python3 -mpytest -p no:cacheprovider test_example.py

[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/pytest.py", line 102, in <module>
[13:54:06]    raise SystemExit(pytest.main())
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/__init__.py", line 55, in main
[13:54:06]    config = _prepareconfig(args, plugins)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/__init__.py", line 200, in _prepareconfig
[13:54:06]    pluginmanager=pluginmanager, args=args
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/pluggy/hooks.py", line 289, in __call__
[13:54:06]    return self._hookexec(self, self.get_hookimpls(), kwargs)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/pluggy/manager.py", line 87, in _hookexec
[13:54:06]    return self._inner_hookexec(hook, methods, kwargs)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/pluggy/manager.py", line 81, in <lambda>
[13:54:06]    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/pluggy/callers.py", line 203, in _multicall
[13:54:06]    gen.send(outcome)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
[13:54:06]    config = outcome.get_result()
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/pluggy/callers.py", line 80, in get_result
[13:54:06]    raise ex[1].with_traceback(ex[2])
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/pluggy/callers.py", line 187, in _multicall
[13:54:06]    res = hook_impl.function(*args)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/__init__.py", line 661, in pytest_cmdline_parse
[13:54:06]    self.parse(args)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/__init__.py", line 869, in parse
[13:54:06]    self._preparse(args, addopts=addopts)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/__init__.py", line 803, in _preparse
[13:54:06]    self._initini(args)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/__init__.py", line 728, in _initini
[13:54:06]    args, namespace=copy.copy(self.option)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/argparsing.py", line 116, in parse_known_and_unknown_args
[13:54:06]    optparser = self._getparser()
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/argparsing.py", line 86, in _getparser
[13:54:06]    optparser = MyOptionParser(self, self.extra_info, prog=self.prog)
[13:54:06]  File "/home/automake/venvs/testenv/lib/python3.5/site-packages/_pytest/config/argparsing.py", line 333, in __init__
[13:54:06]    allow_abbrev=False,
[13:54:06]TypeError: __init__() got an unexpected keyword argument 'allow_abbrev'

Caused by this commit: https://github.com/pytest-dev/pytest/commit/d72fb73fa091534a862dbe462257efeef7ecaa2f

It seems allow_abbrev doesn’t exist as a valid kwarg to argparse.ArgumentParser in Python 3.5.2:

>>> parser = argparse.ArgumentParser(prog='PROG', allow_abbrev=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'allow_abbrev'

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 31 (17 by maintainers)

Most upvoted comments

IDK if it helps or not, but I encountered this problem with pytest 5.2.0 when I pip3 installed an unrelated package which (probably erroneously) installed the 1.4.0 version of argparse over the one installed in the standard library.

unless you’re doing weird things with PYTHONPATH even that shouldn’t matter – site-packages is after the stdlib in sys.path ordering (unless something wacky / incorrect is going on)

the closest I can get is

$ PYTHONPATH=venv/lib/python3.6/site-packages ./venv/bin/pytest t.py
...
TypeError: __init__() got an unexpected keyword argument 'allow_abbrev'

but that’s pretty nonsense :S

I just got this with Python 3.7, but I have no idea why. As I’m about to reinstall everything and I might never see it again, here it is:


platform linux -- Python 3.7.3, pytest-5.0.1, py-1.5.4, pluggy-0.12.0
rootdir: /home/classic/dev/zzzcomputing/release_scripts/_release_work/SQLAlchemy-1.3.6, inifile: setup.cfg
plugins: forked-0.2, xdist-1.29.0
gw0 C / gw1 C / gw2 C / gw3 C[gw0] node down: Traceback (most recent call last):
  File "/home/classic/.venv3/lib/python3.7/site-packages/execnet/gateway_base.py", line 1072, in executetask
    do_exec(co, loc)  # noqa
  File "<string>", line 1, in do_exec
  File "<remote exec>", line 242, in <module>
  File "<remote exec>", line 217, in remote_initconfig
  File "/home/classic/.venv3/lib/python3.7/site-packages/_pytest/config/__init__.py", line 709, in fromdictargs
    config.parse(args, addopts=False)
  File "/home/classic/.venv3/lib/python3.7/site-packages/_pytest/config/__init__.py", line 869, in parse
    self._preparse(args, addopts=addopts)
  File "/home/classic/.venv3/lib/python3.7/site-packages/_pytest/config/__init__.py", line 803, in _preparse
    self._initini(args)
  File "/home/classic/.venv3/lib/python3.7/site-packages/_pytest/config/__init__.py", line 728, in _initini
    args, namespace=copy.copy(self.option)
  File "/home/classic/.venv3/lib/python3.7/site-packages/_pytest/config/argparsing.py", line 116, in parse_known_and_unknown_args
    optparser = self._getparser()
  File "/home/classic/.venv3/lib/python3.7/site-packages/_pytest/config/argparsing.py", line 86, in _getparser
    optparser = MyOptionParser(self, self.extra_info, prog=self.prog)
  File "/home/classic/.venv3/lib/python3.7/site-packages/_pytest/config/argparsing.py", line 333, in __init__
    allow_abbrev=False,
TypeError: __init__() got an unexpected keyword argument 'allow_abbrev'

@hexaclock I suspect you have either a poisoned lib directory (maybe from running virtualenv against the same dir with an older python?) or a poisoned sys.path (maybe from PYTHONPATH environment variable?)

could you provide reproduction steps?