Skip to content

Commit ea2c6b8

Browse files
committed
config: fix consider_preparse with missing argument to -p
This is only required after/with 415899d - otherwise argparse ensures there is an argument already.
1 parent 15ef168 commit ea2c6b8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/_pytest/config/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,10 @@ def consider_preparse(self, args):
481481
i += 1
482482
if isinstance(opt, six.string_types):
483483
if opt == "-p":
484-
parg = args[i]
484+
try:
485+
parg = args[i]
486+
except IndexError:
487+
return
485488
i += 1
486489
elif opt.startswith("-p"):
487490
parg = opt[2:]

testing/test_pluginmanager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ def test_preparse_args(self, pytestpm):
313313
assert '"hello123"' in excinfo.value.args[0]
314314
pytestpm.consider_preparse(["-pno:hello123"])
315315

316+
# Handles -p without following arg (when used without argparse).
317+
pytestpm.consider_preparse(["-p"])
318+
316319
def test_plugin_prevent_register(self, pytestpm):
317320
pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
318321
l1 = pytestpm.get_plugins()

0 commit comments

Comments
 (0)