MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_disable_plugin_autoload

Function test_disable_plugin_autoload

testing/test_config.py:1060–1101  ·  view source on GitHub ↗
(
    pytester: Pytester,
    monkeypatch: MonkeyPatch,
    parse_args: Union[Tuple[str, str], Tuple[()]],
    should_load: bool,
)

Source from the content-addressed store, hash-verified

1058 "parse_args,should_load", [(("-p", "mytestplugin"), True), ((), False)]
1059)
1060def test_disable_plugin_autoload(
1061 pytester: Pytester,
1062 monkeypatch: MonkeyPatch,
1063 parse_args: Union[Tuple[str, str], Tuple[()]],
1064 should_load: bool,
1065) -> None:
1066 class DummyEntryPoint:
1067 project_name = name = "mytestplugin"
1068 group = "pytest11"
1069 version = "1.0"
1070
1071 def load(self):
1072 return sys.modules[self.name]
1073
1074 class Distribution:
1075 metadata = {"name": "foo"}
1076 entry_points = (DummyEntryPoint(),)
1077 files = ()
1078
1079 class PseudoPlugin:
1080 x = 42
1081
1082 attrs_used = []
1083
1084 def __getattr__(self, name):
1085 assert name == "__loader__"
1086 self.attrs_used.append(name)
1087 return object()
1088
1089 def distributions():
1090 return (Distribution(),)
1091
1092 monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
1093 monkeypatch.setattr(importlib_metadata, "distributions", distributions)
1094 monkeypatch.setitem(sys.modules, "mytestplugin", PseudoPlugin()) # type: ignore[misc]
1095 config = pytester.parseconfig(*parse_args)
1096 has_loaded = config.pluginmanager.get_plugin("mytestplugin") is not None
1097 assert has_loaded == should_load
1098 if should_load:
1099 assert PseudoPlugin.attrs_used == ["__loader__"]
1100 else:
1101 assert PseudoPlugin.attrs_used == []
1102
1103
1104def test_plugin_loading_order(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

setenvMethod · 0.80
setattrMethod · 0.80
setitemMethod · 0.80
PseudoPluginClass · 0.70
parseconfigMethod · 0.45

Tested by

no test coverage detected