From 5819536f00ace91660c95ef7d65ff1c425a7b5b8 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 28 Feb 2020 19:41:56 +0100 Subject: [PATCH] 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. --- changelog/6795.improvement.rst | 1 + src/_pytest/config/__init__.py | 6 +++++- testing/test_config.py | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 changelog/6795.improvement.rst diff --git a/changelog/6795.improvement.rst b/changelog/6795.improvement.rst new file mode 100644 index 000000000..b1fd70d8a --- /dev/null +++ b/changelog/6795.improvement.rst @@ -0,0 +1 @@ +Import usage error message with invalid `-o` option. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index b8e0bad99..3107950f6 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -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 diff --git a/testing/test_config.py b/testing/test_config.py index c446a4141..be728c0fc 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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):