Merge pull request #4522 from blueyed/p-no-space
Handle missing space with -p
This commit is contained in:
commit
ebe0a88226
|
@ -0,0 +1 @@
|
||||||
|
``-p`` now accepts its argument without a space between the value, for example ``-pmyplugin``.
|
|
@ -470,9 +470,20 @@ class PytestPluginManager(PluginManager):
|
||||||
#
|
#
|
||||||
|
|
||||||
def consider_preparse(self, args):
|
def consider_preparse(self, args):
|
||||||
for opt1, opt2 in zip(args, args[1:]):
|
i = 0
|
||||||
if opt1 == "-p":
|
n = len(args)
|
||||||
self.consider_pluginarg(opt2)
|
while i < n:
|
||||||
|
opt = args[i]
|
||||||
|
i += 1
|
||||||
|
if isinstance(opt, six.string_types):
|
||||||
|
if opt == "-p":
|
||||||
|
parg = args[i]
|
||||||
|
i += 1
|
||||||
|
elif opt.startswith("-p"):
|
||||||
|
parg = opt[2:]
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
self.consider_pluginarg(parg)
|
||||||
|
|
||||||
def consider_pluginarg(self, arg):
|
def consider_pluginarg(self, arg):
|
||||||
if arg.startswith("no:"):
|
if arg.startswith("no:"):
|
||||||
|
@ -507,7 +518,7 @@ class PytestPluginManager(PluginManager):
|
||||||
# "terminal" or "capture". Those plugins are registered under their
|
# "terminal" or "capture". Those plugins are registered under their
|
||||||
# basename for historic purposes but must be imported with the
|
# basename for historic purposes but must be imported with the
|
||||||
# _pytest prefix.
|
# _pytest prefix.
|
||||||
assert isinstance(modname, (six.text_type, str)), (
|
assert isinstance(modname, six.string_types), (
|
||||||
"module name as text required, got %r" % modname
|
"module name as text required, got %r" % modname
|
||||||
)
|
)
|
||||||
modname = str(modname)
|
modname = str(modname)
|
||||||
|
|
|
@ -323,6 +323,12 @@ class TestPytestPluginManagerBootstrapming(object):
|
||||||
ImportError, lambda: pytestpm.consider_preparse(["xyz", "-p", "hello123"])
|
ImportError, lambda: pytestpm.consider_preparse(["xyz", "-p", "hello123"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Handles -p without space (#3532).
|
||||||
|
with pytest.raises(ImportError) as excinfo:
|
||||||
|
pytestpm.consider_preparse(["-phello123"])
|
||||||
|
assert '"hello123"' in excinfo.value.args[0]
|
||||||
|
pytestpm.consider_preparse(["-pno:hello123"])
|
||||||
|
|
||||||
def test_plugin_prevent_register(self, pytestpm):
|
def test_plugin_prevent_register(self, pytestpm):
|
||||||
pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
|
pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
|
||||||
l1 = pytestpm.get_plugins()
|
l1 = pytestpm.get_plugins()
|
||||||
|
|
Loading…
Reference in New Issue