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

Issue: 3103 - Fix UsageError raised when specifying config override options followed by test path #3133

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Anthon van der Neut
Anthony Sottile
Antony Lee
Armin Rigo
Aron Coyle
Aron Curzon
Aviv Palivoda
Barney Gale
Expand Down
5 changes: 4 additions & 1 deletion _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,12 +1191,15 @@ def _get_override_ini_value(self, name):
# 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
first_override_set = False
for ini_config_list in self._override_ini:
for ini_config in ini_config_list:
try:
(key, user_ini_value) = ini_config.split("=", 1)
first_override_set = True
except ValueError:
raise UsageError("-o/--override-ini expects option=value style.")
if not first_override_set:
raise UsageError("-o/--override-ini expects option=value style.")
if key == name:
value = user_ini_value
return value
Expand Down
1 change: 1 addition & 0 deletions changelog/3103.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``UsageError`` being raised when specifying ``-o/--override`` command-line option followed by a test path.
14 changes: 14 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,3 +860,17 @@ def test_addopts_before_initini(self, testdir, tmpdir, monkeypatch):
config = get_config()
config._preparse([], addopts=True)
assert config._override_ini == [['cache_dir=%s' % cache_dir]]

def test_no_error_if_true_first_key_value_pair(self, testdir, request):
"""Ensure a file path following a '-o' option does not generate an error (#3103)"""
testdir.makeini("""
[pytest]
xdist_strict=False
""")
testdir.makepyfile("""
def test():
pass
""")
result = testdir.runpytest('--override-ini', 'xdist_strict=True', '{}.py'.format(request.node.name))
assert 'ERROR:' not in result.stderr.str()
result.stdout.fnmatch_lines('* 1 passed in *')