diff --git a/AUTHORS b/AUTHORS index 862378be9f5..ab1b2152ba1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,6 +17,7 @@ Anthon van der Neut Anthony Sottile Antony Lee Armin Rigo +Aron Coyle Aron Curzon Aviv Palivoda Barney Gale diff --git a/_pytest/config.py b/_pytest/config.py index ce7468f7204..f44bdb4c4cc 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -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 diff --git a/changelog/3103.bugfix b/changelog/3103.bugfix new file mode 100644 index 00000000000..ec493eb4efd --- /dev/null +++ b/changelog/3103.bugfix @@ -0,0 +1 @@ +Fix ``UsageError`` being raised when specifying ``-o/--override`` command-line option followed by a test path. diff --git a/testing/test_config.py b/testing/test_config.py index 5202b21b98e..debedb28375 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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 *')