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.
This commit is contained in:
Daniel Hahler 2020-02-28 19:41:56 +01:00 committed by GitHub
parent 952cab2d85
commit 5819536f00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -0,0 +1 @@
Import usage error message with invalid `-o` option.

View File

@ -1131,7 +1131,11 @@ class Config:
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

View File

@ -1089,8 +1089,12 @@ class TestOverrideIniArgs:
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):