Example #1
0
 def test_plugin_prevent_register(self, pytestpm: PytestPluginManager) -> None:
     pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
     l1 = pytestpm.get_plugins()
     pytestpm.register(42, name="abc")
     l2 = pytestpm.get_plugins()
     assert len(l2) == len(l1)
     assert 42 not in l2
 def __recreate__(self):
     new_pm = PytestPluginManager()
     for plugin in self._1_plugins:
         new_pm.register(plugin)
         if hasattr(plugin, '__reinit__'):
             plugin.__reinit__(new_pm)
     return new_pm
 def test_plugin_prevent_register_unregistered_alredy_registered(
         self, pytestpm: PytestPluginManager) -> None:
     pytestpm.register(42, name="abc")
     l1 = pytestpm.get_plugins()
     assert 42 in l1
     pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
     l2 = pytestpm.get_plugins()
     assert 42 not in l2
Example #4
0
 def test_register_imported_modules(self):
     pm = PytestPluginManager()
     mod = py.std.types.ModuleType("x.y.pytest_hello")
     pm.register(mod)
     assert pm.is_registered(mod)
     values = pm.get_plugins()
     assert mod in values
     pytest.raises(ValueError, "pm.register(mod)")
     pytest.raises(ValueError, lambda: pm.register(mod))
     # assert not pm.is_registered(mod2)
     assert pm.get_plugins() == values
    def test_plugin_prevent_register_stepwise_on_cacheprovider_unregister(
            self, pytestpm: PytestPluginManager) -> None:
        """From PR #4304: The only way to unregister a module is documented at
        the end of https://docs.pytest.org/en/stable/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