(
pytester: Pytester,
monkeypatch: MonkeyPatch,
parse_args: Union[Tuple[str, str], Tuple[()]],
should_load: bool,
)
| 1058 | "parse_args,should_load", [(("-p", "mytestplugin"), True), ((), False)] |
| 1059 | ) |
| 1060 | def 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 | |
| 1104 | def test_plugin_loading_order(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected