Skip to content

Commit 5819536

Browse files
authored
Improve UsageError with invalid -o style (#6795)
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.
1 parent 952cab2 commit 5819536

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

changelog/6795.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Import usage error message with invalid `-o` option.

src/_pytest/config/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,11 @@ def _get_override_ini_value(self, name: str) -> Optional[str]:
11311131
try:
11321132
key, user_ini_value = ini_config.split("=", 1)
11331133
except ValueError:
1134-
raise UsageError("-o/--override-ini expects option=value style.")
1134+
raise UsageError(
1135+
"-o/--override-ini expects option=value style (got: {!r}).".format(
1136+
ini_config
1137+
)
1138+
)
11351139
else:
11361140
if key == name:
11371141
value = user_ini_value

testing/test_config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,12 @@ def test_override_ini_usage_error_bad_style(self, testdir):
10891089
xdist_strict=False
10901090
"""
10911091
)
1092-
result = testdir.runpytest("--override-ini", "xdist_strict True", "-s")
1093-
result.stderr.fnmatch_lines(["*ERROR* *expects option=value*"])
1092+
result = testdir.runpytest("--override-ini", "xdist_strict", "True")
1093+
result.stderr.fnmatch_lines(
1094+
[
1095+
"ERROR: -o/--override-ini expects option=value style (got: 'xdist_strict').",
1096+
]
1097+
)
10941098

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

0 commit comments

Comments
 (0)