From af4143729f04fdbe8ecd206d40ceb58c07da56f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannick=20P=C3=89ROUX?= Date: Sat, 21 Jan 2023 12:22:44 +0100 Subject: [PATCH] Allow spaces in -p arguments (#10658) --- AUTHORS | 1 + changelog/10658.improvement.rst | 3 +++ src/_pytest/config/__init__.py | 1 + testing/test_config.py | 4 ++++ 4 files changed, 9 insertions(+) create mode 100644 changelog/10658.improvement.rst diff --git a/AUTHORS b/AUTHORS index fe60b6865..ceb19559e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -378,6 +378,7 @@ Wouter van Ackooy Xixi Zhao Xuan Luong Xuecong Liao +Yannick PĂ©roux Yoav Caspi Yuliang Shao Yusuke Kadowaki diff --git a/changelog/10658.improvement.rst b/changelog/10658.improvement.rst new file mode 100644 index 000000000..54e5ae84f --- /dev/null +++ b/changelog/10658.improvement.rst @@ -0,0 +1,3 @@ +Allow ``-p`` arguments to include spaces (eg: ``-p no:logging`` instead of +``-pno:logging``). Mostly useful in the ``addopts`` section of the configuration +file. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index a08a965a6..b4dbc0da4 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -697,6 +697,7 @@ class PytestPluginManager(PluginManager): parg = opt[2:] else: continue + parg = parg.strip() if exclude_only and not parg.startswith("no:"): continue self.consider_pluginarg(parg) diff --git a/testing/test_config.py b/testing/test_config.py index db50869c5..35e2a601c 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -1808,6 +1808,10 @@ def test_config_does_not_load_blocked_plugin_from_args(pytester: Pytester) -> No result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"]) assert result.ret == ExitCode.USAGE_ERROR + result = pytester.runpytest(str(p), "-p no:capture", "-s") + result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"]) + assert result.ret == ExitCode.USAGE_ERROR + def test_invocation_args(pytester: Pytester) -> None: """Ensure that Config.invocation_* arguments are correctly defined"""