Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'testpaths' exception raised when using --override-ini command line option #2105

Closed
mbukatov opened this issue Nov 30, 2016 · 5 comments

Comments

@mbukatov
Copy link

Summary of the issue

When I use --override-ini feature while specifying particular test to run, py.test crashes with KeyError: 'testpaths' exception.

Description of a reproducer

Create minimal test case in ~/tmp directory so that:

$ cd ~/tmp
$ ls
test_foo.py
$ cat test_foo.py
def test_foo():
    assert True

Execution of this test case works as expected:

$ py.test 
============================== test session starts ===============================
platform linux -- Python 3.5.1, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
rootdir: /home/usmqe/tmp, inifile: 
collected 1 items 

test_foo.py .

============================ 1 passed in 0.01 seconds ===========================

And there are no problems with invocations listed below either:

  • py.test test_foo.py
  • py.test --override-ini xfail_strict=True

But when I both reconfigure any configuration option via --override-ini and specify a test case at the same time, py.test crashes:

$ py.test --override-ini xfail_strict=True test_foo.py 
Traceback (most recent call last):
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/config.py", line 1064, in getini
    return self._inicache[name]
KeyError: 'testpaths'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/usmqe/.local/bin/py.test", line 11, in <module>
    sys.exit(main())
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/config.py", line 47, in main
    config = _prepareconfig(args, plugins)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/config.py", line 132, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/helpconfig.py", line 32, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
    self.result = func()
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/config.py", line 882, in pytest_cmdline_parse
    self.parse(args)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/config.py", line 1045, in parse
    args = self.getini('testpaths')
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/config.py", line 1066, in getini
    self._inicache[name] = val = self._getini(name)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/config.py", line 1074, in _getini
    value = self._get_override_ini_value(name)
  File "/home/usmqe/.local/lib/python3.5/site-packages/_pytest/config.py", line 1123, in _get_override_ini_value
    (key, user_ini_value) = ini_config.split("=", 1)
ValueError: not enough values to unpack (expected 2, got 1)

Enviroment

I'm using Python 3.5.1 (from rh-python35 collection on RHEL 7):

$ python --version
Python 3.5.1
$ rpm -qf $(which python)
rh-python35-python-3.5.1-6.el7.x86_64

And Pytest 3.0.4:

$ py.test --version
This is pytest version 3.0.4, imported from /home/usmqe/.local/lib/python3.5/site-packages/pytest.py

The rest of python environment:

$ pip list
You are using pip version 7.1.0, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
docutils (0.12)
Jinja2 (2.8)
MarkupSafe (0.23)
mrglog (0.1.1)
pip (7.1.0)
plumbum (1.6.2)
py (1.4.31)
pytest (3.0.4)
PyYAML (3.10)
requests (2.11.1)
setuptools (18.0.1)
virtualenv (13.1.2)
@mbukatov
Copy link
Author

I reproduced this on Fedora 24 in clean virtualenv with packages listed below as well:

$ pip list --format=legacy
pip (9.0.1)
py (1.4.31)
pytest (3.0.4)
setuptools (29.0.1)
wheel (0.30.0a0)

@decentral1se
Copy link
Contributor

decentral1se commented Nov 30, 2016

Oh, that's because the code does (source):

(key, user_ini_value) = ini_config.split("=", 1)

@mbukatov, everything should work when you run:

$ pytest --override-ini=xfail_strict=True test_foo.py

Not sure if pytest supports --override-ini Foo as well as --override-ini=Foo? This should probably recommend to pass the = instead of blowing up. Will submit a PR once someone give some direction.

@nicoddemus
Copy link
Member

Not sure if pytest supports --override-ini Foo as well as --override-ini=Foo?

Not sure either, I think argparse handles that.

This should probably recommend to pass the = instead of blowing up.

I agree, I think it is sensible to check if = is not present in the option value and raise an UsageError giving a hint about always prefer passing =.

mbukatov added a commit to usmqe/usmqe-tests that referenced this issue Dec 1, 2016
@mbukatov
Copy link
Author

mbukatov commented Dec 1, 2016

@lwm thanks for looking into this

@decentral1se
Copy link
Contributor

Not sure if pytest supports --override-ini Foo as well as --override-ini=Foo?

Not sure either, I think argparse handles that.

Yes, argparse handles this but only for parsing arguments to --override-ini, not the values of the arguments. I've added some changes in #2108.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants