diff --git a/AUTHORS b/AUTHORS index dabeb1c06..777eda324 100644 --- a/AUTHORS +++ b/AUTHORS @@ -76,6 +76,7 @@ Endre Galaczi Eric Hunsberger Eric Siegerman Erik M. Bray +Fabien Zarifian Fabio Zadrozny Feng Ma Florian Bruhin diff --git a/changelog/4304.bugfix.rst b/changelog/4304.bugfix.rst new file mode 100644 index 000000000..7d4dc033e --- /dev/null +++ b/changelog/4304.bugfix.rst @@ -0,0 +1 @@ +Block the ``stepwise`` plugin if ``cacheprovider`` is also blocked, as one depends on the other. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index b42d6f843..0fc895546 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -477,6 +477,11 @@ class PytestPluginManager(PluginManager): def consider_pluginarg(self, arg): if arg.startswith("no:"): name = arg[3:] + # PR #4304 : remove stepwise if cacheprovider is blocked + if name == "cacheprovider": + self.set_blocked("stepwise") + self.set_blocked("pytest_stepwise") + self.set_blocked(name) if not name.startswith("pytest_"): self.set_blocked("pytest_" + name) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 0bee415f2..8e35290b7 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -380,3 +380,21 @@ class TestPytestPluginManagerBootstrapming(object): pytestpm.consider_preparse(["xyz", "-p", "no:abc"]) l2 = pytestpm.get_plugins() assert 42 not in l2 + + def test_plugin_prevent_register_stepwise_on_cacheprovider_unregister( + self, pytestpm + ): + """ From PR #4304 : The only way to unregister a module is documented at + the end of https://docs.pytest.org/en/latest/plugins.html. + + When unregister cacheprovider, then unregister stepwise too + """ + pytestpm.register(42, name="cacheprovider") + pytestpm.register(43, name="stepwise") + l1 = pytestpm.get_plugins() + assert 42 in l1 + assert 43 in l1 + pytestpm.consider_preparse(["xyz", "-p", "no:cacheprovider"]) + l2 = pytestpm.get_plugins() + assert 42 not in l2 + assert 43 not in l2