Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle -p plug after -p no:plug #4936

Merged
merged 1 commit into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")