Skip to content

Add warning for incorrect passing args to -o. #2108

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

Merged
merged 1 commit into from
Dec 1, 2016
Merged
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
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