def test_blocked_plugin_can_be_used(self, pytestpm: PytestPluginManager) -> None: 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")
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 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
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
def test_preparse_args(self, pytestpm: PytestPluginManager) -> None: pytest.raises( ImportError, lambda: pytestpm.consider_preparse(["xyz", "-p", "hello123"]) ) # Handles -p without space (#3532). with pytest.raises(ImportError) as excinfo: pytestpm.consider_preparse(["-phello123"]) assert '"hello123"' in excinfo.value.args[0] pytestpm.consider_preparse(["-pno:hello123"]) # Handles -p without following arg (when used without argparse). pytestpm.consider_preparse(["-p"]) with pytest.raises(UsageError, match="^plugin main cannot be disabled$"): pytestpm.consider_preparse(["-p", "no:main"])