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

Method test_no_meta_path_found

testing/test_pathlib.py:297–312  ·  view source on GitHub ↗

Even without any meta_path should still import module.

(
        self, simple_module: Path, monkeypatch: MonkeyPatch, tmp_path: Path
    )

Source from the content-addressed store, hash-verified

295 assert module1 is not module2
296
297 def test_no_meta_path_found(
298 self, simple_module: Path, monkeypatch: MonkeyPatch, tmp_path: Path
299 ) -> None:
300 """Even without any meta_path should still import module."""
301 monkeypatch.setattr(sys, "meta_path", [])
302 module = import_path(simple_module, mode="importlib", root=tmp_path)
303 assert module.foo(2) == 42 # type: ignore[attr-defined]
304
305 # mode='importlib' fails if no spec is found to load the module
306 import importlib.util
307
308 monkeypatch.setattr(
309 importlib.util, "spec_from_file_location", lambda *args: None
310 )
311 with pytest.raises(ImportError):
312 import_path(simple_module, mode="importlib", root=tmp_path)
313
314
315def test_resolve_package_path(tmp_path: Path) -> None:

Callers

nothing calls this directly

Calls 3

import_pathFunction · 0.90
setattrMethod · 0.80
fooMethod · 0.45

Tested by

no test coverage detected