Skip to content

Commit

Permalink
Improve UsageError with invalid -o style (pytest-dev#6795)
Browse files Browse the repository at this point in the history
This started from fixing the test, where `"xdist_strict True"` was used
as a single argument, although you typically would see `["xdist_strict",
"True"]`.

Improves the error message to mention the option that caused the error.
  • Loading branch information
blueyed authored and aklajnert committed Feb 29, 2020
1 parent 3f1bc62 commit b7aed7e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/6795.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Import usage error message with invalid `-o` option.
6 changes: 5 additions & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,11 @@ def _get_override_ini_value(self, name: str) -> Optional[str]:
try:
key, user_ini_value = ini_config.split("=", 1)
except ValueError:
raise UsageError("-o/--override-ini expects option=value style.")
raise UsageError(
"-o/--override-ini expects option=value style (got: {!r}).".format(
ini_config
)
)
else:
if key == name:
value = user_ini_value
Expand Down
8 changes: 6 additions & 2 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,12 @@ def test_override_ini_usage_error_bad_style(self, testdir):
xdist_strict=False
"""
)
result = testdir.runpytest("--override-ini", "xdist_strict True", "-s")
result.stderr.fnmatch_lines(["*ERROR* *expects option=value*"])
result = testdir.runpytest("--override-ini", "xdist_strict", "True")
result.stderr.fnmatch_lines(
[
"ERROR: -o/--override-ini expects option=value style (got: 'xdist_strict').",
]
)

@pytest.mark.parametrize("with_ini", [True, False])
def test_override_ini_handled_asap(self, testdir, with_ini):
Expand Down

0 comments on commit b7aed7e

Please sign in to comment.