From ea2c6b8a88c1e167a086efa2fc697f72885e8ace Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 21 Mar 2019 04:38:11 +0100 Subject: [PATCH] config: fix consider_preparse with missing argument to -p This is only required after/with 415899d4 - otherwise argparse ensures there is an argument already. --- src/_pytest/config/__init__.py | 5 ++++- testing/test_pluginmanager.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index b2e4fd774..41519595f 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -481,7 +481,10 @@ class PytestPluginManager(PluginManager): i += 1 if isinstance(opt, six.string_types): if opt == "-p": - parg = args[i] + try: + parg = args[i] + except IndexError: + return i += 1 elif opt.startswith("-p"): parg = opt[2:] diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 4e0c0ed1e..6b44f3e0c 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -313,6 +313,9 @@ class TestPytestPluginManagerBootstrapming(object): assert '"hello123"' in excinfo.value.args[0] pytestpm.consider_preparse(["-pno:hello123"]) + # Handles -p without following arg (when used without argparse). + pytestpm.consider_preparse(["-p"]) + def test_plugin_prevent_register(self, pytestpm): pytestpm.consider_preparse(["xyz", "-p", "no:abc"]) l1 = pytestpm.get_plugins()