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

Method test_pkgfile

testing/test_collection.py:701–722  ·  view source on GitHub ↗

Verify nesting when a module is within a package. The parent chain should match: Module<x.py> -> Package<subdir> -> Session. Session's parent should always be None.

(self, pytester: Pytester, monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

699 assert parent.config is config
700
701 def test_pkgfile(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
702 """Verify nesting when a module is within a package.
703 The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
704 Session&#x27;s parent should always be None.
705 """
706 tmp_path = pytester.path
707 subdir = tmp_path.joinpath("subdir")
708 x = ensure_file(subdir / "x.py")
709 ensure_file(subdir / "__init__.py")
710 with monkeypatch.context() as mp:
711 mp.chdir(subdir)
712 config = pytester.parseconfigure(x)
713 col = pytester.getnode(config, x)
714 assert col is not None
715 assert col.name == "x.py"
716 assert isinstance(col, pytest.Module)
717 assert isinstance(col.parent, pytest.Package)
718 assert isinstance(col.parent.parent, pytest.Session)
719 # session is batman (has no parents)
720 assert col.parent.parent.parent is None
721 for parent in col.listchain():
722 assert parent.config is config
723
724
725class Test_genitems:

Callers

nothing calls this directly

Calls 6

ensure_fileFunction · 0.85
contextMethod · 0.80
listchainMethod · 0.80
chdirMethod · 0.45
parseconfigureMethod · 0.45
getnodeMethod · 0.45

Tested by

no test coverage detected