Skip to content

Commit

Permalink
Merge pull request #2108 from lwm/exp-2105
Browse files Browse the repository at this point in the history
Add warning for incorrect passing args to `-o`.
  • Loading branch information
RonnyPfannschmidt authored Dec 1, 2016
2 parents e612619 + c856537 commit 9ed3d76
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
3.0.5.dev0
==========

* Add warning when not passing ``option=value`` correctly to ``-o/--override-ini`` (`#2105`_).
Also improved the help documentation. Thanks to `@mbukatov`_ for the report and
`@lwm`_ for the PR.

* Now ``--confcutdir`` and ``--junit-xml`` are properly validated if they are directories
and filenames, respectively (`#2089`_ and `#2078`_). Thanks to `@lwm`_ for the PR.

Expand Down Expand Up @@ -30,6 +34,7 @@

*

.. _@mbukatov: https://github.com/mbukatov
.. _@dupuy: https://bitbucket.org/dupuy/
.. _@lwm: https://github.com/lwm
.. _@adler-j: https://github.com/adler-j
Expand All @@ -45,6 +50,7 @@
.. _#2078: https://github.com/pytest-dev/pytest/issues/2078
.. _#2082: https://github.com/pytest-dev/pytest/issues/2082
.. _#2103: https://github.com/pytest-dev/pytest/issues/2103
.. _#2105: https://github.com/pytest-dev/pytest/issues/2105


3.0.4
Expand Down
5 changes: 4 additions & 1 deletion _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,10 @@ def _get_override_ini_value(self, name):
if self.getoption("override_ini", None):
for ini_config_list in self.option.override_ini:
for ini_config in ini_config_list:
(key, user_ini_value) = ini_config.split("=", 1)
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
Expand Down
2 changes: 1 addition & 1 deletion _pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def pytest_addoption(parser):
group._addoption(
'-o', '--override-ini', nargs='*', dest="override_ini",
action="append",
help="override config option, e.g. `-o xfail_strict=True`.")
help="override config option with option=value style, e.g. `-o xfail_strict=True`.")


@pytest.hookimpl(hookwrapper=True)
Expand Down
10 changes: 9 additions & 1 deletion testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_confcutdir(self, testdir):
""")
result = testdir.inline_run("--confcutdir=.")
assert result.ret == 0

class TestConfigCmdlineParsing:
def test_parsing_again_fails(self, testdir):
config = testdir.parseconfig()
Expand Down Expand Up @@ -732,6 +732,14 @@ def test_multiple_options(pytestconfig):
"ini3:True",
"ini4:False"])

def test_override_ini_usage_error_bad_style(self, testdir):
testdir.makeini("""
[pytest]
xdist_strict=False
""")
result = testdir.runpytest("--override-ini", 'xdist_strict True', "-s")
result.stderr.fnmatch_lines(["*ERROR* *expects option=value*"])

def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch):
monkeypatch.chdir(str(tmpdir))
a = tmpdir.mkdir("a")
Expand Down

0 comments on commit 9ed3d76

Please sign in to comment.