Skip to content

Commit

Permalink
Merge pull request #4936 from blueyed/use-blocked-plugin
Browse files Browse the repository at this point in the history
Handle `-p plug` after `-p no:plug`
  • Loading branch information
nicoddemus authored Mar 16, 2019
2 parents c1e01c2 + 15fe8c6 commit 5d14362
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog/4936.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Handle ``-p plug`` after ``-p no:plug``.

This can be used to override a blocked plugin (e.g. in "addopts") from the
command line etc.
8 changes: 8 additions & 0 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,14 @@ def consider_pluginarg(self, arg):
if not name.startswith("pytest_"):
self.set_blocked("pytest_" + name)
else:
name = arg
# Unblock the plugin. None indicates that it has been blocked.
# There is no interface with pluggy for this.
if self._name2plugin.get(name, -1) is None:
del self._name2plugin[name]
if not name.startswith("pytest_"):
if self._name2plugin.get("pytest_" + name, -1) is None:
del self._name2plugin["pytest_" + name]
self.import_plugin(arg, consider_entry_points=True)

def consider_conftest(self, conftestmodule):
Expand Down
7 changes: 7 additions & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,10 @@ def test_plugin_prevent_register_stepwise_on_cacheprovider_unregister(
l2 = pytestpm.get_plugins()
assert 42 not in l2
assert 43 not in l2

def test_blocked_plugin_can_be_used(self, pytestpm):
pytestpm.consider_preparse(["xyz", "-p", "no:abc", "-p", "abc"])

assert pytestpm.has_plugin("abc")
assert not pytestpm.is_blocked("abc")
assert not pytestpm.is_blocked("pytest_abc")

0 comments on commit 5d14362

Please sign in to comment.