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

Method test_pkgfile

testing/test_collection.py:654–674  ·  view source on GitHub ↗

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

(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

652 assert parent.config is config
653
654 def test_pkgfile(self, pytester: Pytester) -> None:
655 """Verify nesting when a module is within a package.
656 The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
657 Session&#x27;s parent should always be None.
658 """
659 tmp_path = pytester.path
660 subdir = tmp_path.joinpath("subdir")
661 x = ensure_file(subdir / "x.py")
662 ensure_file(subdir / "__init__.py")
663 with subdir.cwd():
664 config = pytester.parseconfigure(x)
665 col = pytester.getnode(config, x)
666 assert col is not None
667 assert col.name == "x.py"
668 assert isinstance(col, pytest.Module)
669 assert isinstance(col.parent, pytest.Package)
670 assert isinstance(col.parent.parent, pytest.Session)
671 # session is batman (has no parents)
672 assert col.parent.parent.parent is None
673 for parent in col.listchain():
674 assert parent.config is config
675
676
677class Test_genitems:

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected