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

UsageError raised when specifying config override options followed by test path(s) #3103

Closed
davehunt opened this issue Jan 10, 2018 · 8 comments
Labels
good first issue easy issue that is friendly to new contributor topic: config related to config handling, argument parsing and config file type: bug problem that needs to be addressed

Comments

@davehunt
Copy link
Contributor

Summary

When using -o or --override-ini followed by one or more test paths, the session terminates with "ERROR: -o/--override-ini expects option=value style."

pipenv graph

pytest==3.3.2
  - attrs [required: >=17.2.0, installed: 17.4.0]
  - pluggy [required: <0.7,>=0.5, installed: 0.6.0]
  - py [required: >=1.5.0, installed: 1.5.2]
  - setuptools [required: Any, installed: 38.2.5]
  - six [required: >=1.10.0, installed: 1.11.0]

Operating System:

macOS High Sierra 10.13.2

Example:

$ pytest -o console_output_style=classic test.py
ERROR: -o/--override-ini expects option=value style.

The relevant code is below. I would suggest that we only raise the exception if the first value does not contain an '=', and stop considering values as overrides as soon as they no longer contain the character.

pytest/_pytest/config.py

Lines 1188 to 1202 in cf9b31b

def _get_override_ini_value(self, name):
value = None
# override_ini is a list of list, to support both -o foo1=bar1 foo2=bar2 and
# and -o foo1=bar1 -o foo2=bar2 options
# always use the last item if multiple value set for same ini-name,
# e.g. -o foo=bar1 -o foo=bar2 will set foo to bar2
for ini_config_list in self._override_ini:
for ini_config in ini_config_list:
try:
(key, user_ini_value) = ini_config.split("=", 1)
except ValueError:
raise UsageError("-o/--override-ini expects option=value style.")
if key == name:
value = user_ini_value
return value

@pytestbot
Copy link
Contributor

GitMate.io thinks the contributor most likely able to help you is @nicoddemus.

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jan 10, 2018
@nicoddemus
Copy link
Member

. I would suggest that we only raise the exception if the first value does not contain an '=', and stop considering values as overrides as soon as they no longer contain the character.

Sounds reasonable, thanks @davehunt!

@nicoddemus nicoddemus added good first issue easy issue that is friendly to new contributor topic: config related to config handling, argument parsing and config file labels Jan 10, 2018
@arcoyle
Copy link

arcoyle commented Jan 14, 2018

Hi @davehunt, @nicoddemus
I can take a look at this if there is no work already underway?
I am a first time contributor

@nicoddemus
Copy link
Member

@arcoyle thanks, we appreciate! Please go ahead! 😁

If you get stuck, feel free to open a PR anyway so we can help out over the code you managed to do so far.

@arcoyle
Copy link

arcoyle commented Jan 20, 2018

@nicoddemus I have opened a PR for this issue, could you please review.

One thing I noticed while testing was the use of switch options before the test path stops the exception. Nothing is added to the list of key value pairs after the switch option.
For example if I take out the fix and run the test with a -o console_output_style=classic -s test.py it won't raise the exception.
This is because of how the argparse module behaves. Just thought it would be interesting to note as it could cause some tests to mask the issue.

@wagnerluis1982
Copy link

Hi, I'd love to contribute to pytest.

My first contribution is checking if this issue is still relevant 😄. In my machine I can't reproduce this bug. I'm using the last version (3.4.0).

@davehunt
Copy link
Contributor Author

davehunt commented Feb 9, 2018

Sorry @wagnerluis1982 this was already resolved by #3147

@davehunt davehunt closed this as completed Feb 9, 2018
@nicoddemus
Copy link
Member

nicoddemus commented Feb 9, 2018

@wagnerluis1982 thanks for your interest in contributing, we really appreciate it. Triaging issues to see if they are still relevant (like you did now) is something that's also very helpful. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor topic: config related to config handling, argument parsing and config file type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

5 participants