MCPcopy
hub / github.com/pytest-dev/pytest / test_check_filepath_consistency

Method test_check_filepath_consistency

testing/test_pathlib.py:298–326  ·  testing/test_pathlib.py::TestImportPath.test_check_filepath_consistency
(
        self, monkeypatch: MonkeyPatch, tmp_path: Path, ns_param: bool
    )

Source from the content-addressed store, hash-verified

296 assert module1 is mod1
297
298 def test_check_filepath_consistency(
299 self, monkeypatch: MonkeyPatch, tmp_path: Path, ns_param: bool
300 ) -> None:
301 name = class="st">"pointsback123"
302 p = tmp_path.joinpath(name + class="st">".py")
303 p.touch()
304 with monkeypatch.context() as mp:
305 for ending in (class="st">".pyc", class="st">".pyo"):
306 mod = ModuleType(name)
307 pseudopath = tmp_path.joinpath(name + ending)
308 pseudopath.touch()
309 mod.__file__ = str(pseudopath)
310 mp.setitem(sys.modules, name, mod)
311 newmod = import_path(
312 p, root=tmp_path, consider_namespace_packages=ns_param
313 )
314 assert mod == newmod
315 mod = ModuleType(name)
316 pseudopath = tmp_path.joinpath(name + class="st">"123.py")
317 pseudopath.touch()
318 mod.__file__ = str(pseudopath)
319 monkeypatch.setitem(sys.modules, name, mod)
320 with pytest.raises(ImportPathMismatchError) as excinfo:
321 import_path(p, root=tmp_path, consider_namespace_packages=ns_param)
322 modname, modfile, orig = excinfo.value.args
323 assert modname == name
324 assert modfile == str(pseudopath)
325 assert orig == p
326 assert issubclass(ImportPathMismatchError, ImportError)
327
328 def test_ensuresyspath_append(self, tmp_path: Path, ns_param: bool) -> None:
329 root1 = tmp_path / class="st">"root1"

Callers

nothing calls this directly

Calls 3

import_pathFunction · 0.90
contextMethod · 0.80
setitemMethod · 0.80

Tested by

no test coverage detected