Skip to content

Commit 5d14362

Browse files
authored
Merge pull request #4936 from blueyed/use-blocked-plugin
Handle `-p plug` after `-p no:plug`
2 parents c1e01c2 + 15fe8c6 commit 5d14362

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

changelog/4936.feature.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Handle ``-p plug`` after ``-p no:plug``.
2+
3+
This can be used to override a blocked plugin (e.g. in "addopts") from the
4+
command line etc.

src/_pytest/config/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ def consider_pluginarg(self, arg):
496496
if not name.startswith("pytest_"):
497497
self.set_blocked("pytest_" + name)
498498
else:
499+
name = arg
500+
# Unblock the plugin. None indicates that it has been blocked.
501+
# There is no interface with pluggy for this.
502+
if self._name2plugin.get(name, -1) is None:
503+
del self._name2plugin[name]
504+
if not name.startswith("pytest_"):
505+
if self._name2plugin.get("pytest_" + name, -1) is None:
506+
del self._name2plugin["pytest_" + name]
499507
self.import_plugin(arg, consider_entry_points=True)
500508

501509
def consider_conftest(self, conftestmodule):

testing/test_pluginmanager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,10 @@ def test_plugin_prevent_register_stepwise_on_cacheprovider_unregister(
346346
l2 = pytestpm.get_plugins()
347347
assert 42 not in l2
348348
assert 43 not in l2
349+
350+
def test_blocked_plugin_can_be_used(self, pytestpm):
351+
pytestpm.consider_preparse(["xyz", "-p", "no:abc", "-p", "abc"])
352+
353+
assert pytestpm.has_plugin("abc")
354+
assert not pytestpm.is_blocked("abc")
355+
assert not pytestpm.is_blocked("pytest_abc")

0 commit comments

Comments
 (0)