Skip to content

Commit 9ed3d76

Browse files
Merge pull request #2108 from lwm/exp-2105
Add warning for incorrect passing args to `-o`.
2 parents e612619 + c856537 commit 9ed3d76

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

CHANGELOG.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
3.0.5.dev0
22
==========
33

4+
* Add warning when not passing ``option=value`` correctly to ``-o/--override-ini`` (`#2105`_).
5+
Also improved the help documentation. Thanks to `@mbukatov`_ for the report and
6+
`@lwm`_ for the PR.
7+
48
* Now ``--confcutdir`` and ``--junit-xml`` are properly validated if they are directories
59
and filenames, respectively (`#2089`_ and `#2078`_). Thanks to `@lwm`_ for the PR.
610

@@ -30,6 +34,7 @@
3034

3135
*
3236

37+
.. _@mbukatov: https://github.com/mbukatov
3338
.. _@dupuy: https://bitbucket.org/dupuy/
3439
.. _@lwm: https://github.com/lwm
3540
.. _@adler-j: https://github.com/adler-j
@@ -45,6 +50,7 @@
4550
.. _#2078: https://github.com/pytest-dev/pytest/issues/2078
4651
.. _#2082: https://github.com/pytest-dev/pytest/issues/2082
4752
.. _#2103: https://github.com/pytest-dev/pytest/issues/2103
53+
.. _#2105: https://github.com/pytest-dev/pytest/issues/2105
4854

4955

5056
3.0.4

_pytest/config.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,10 @@ def _get_override_ini_value(self, name):
11491149
if self.getoption("override_ini", None):
11501150
for ini_config_list in self.option.override_ini:
11511151
for ini_config in ini_config_list:
1152-
(key, user_ini_value) = ini_config.split("=", 1)
1152+
try:
1153+
(key, user_ini_value) = ini_config.split("=", 1)
1154+
except ValueError:
1155+
raise UsageError("-o/--override-ini expects option=value style.")
11531156
if key == name:
11541157
value = user_ini_value
11551158
return value

_pytest/helpconfig.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def pytest_addoption(parser):
2323
group._addoption(
2424
'-o', '--override-ini', nargs='*', dest="override_ini",
2525
action="append",
26-
help="override config option, e.g. `-o xfail_strict=True`.")
26+
help="override config option with option=value style, e.g. `-o xfail_strict=True`.")
2727

2828

2929
@pytest.hookimpl(hookwrapper=True)

testing/test_config.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_confcutdir(self, testdir):
8383
""")
8484
result = testdir.inline_run("--confcutdir=.")
8585
assert result.ret == 0
86-
86+
8787
class TestConfigCmdlineParsing:
8888
def test_parsing_again_fails(self, testdir):
8989
config = testdir.parseconfig()
@@ -732,6 +732,14 @@ def test_multiple_options(pytestconfig):
732732
"ini3:True",
733733
"ini4:False"])
734734

735+
def test_override_ini_usage_error_bad_style(self, testdir):
736+
testdir.makeini("""
737+
[pytest]
738+
xdist_strict=False
739+
""")
740+
result = testdir.runpytest("--override-ini", 'xdist_strict True', "-s")
741+
result.stderr.fnmatch_lines(["*ERROR* *expects option=value*"])
742+
735743
def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch):
736744
monkeypatch.chdir(str(tmpdir))
737745
a = tmpdir.mkdir("a")

0 commit comments

Comments
 (0)