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

Method test_getparent_and_accessors

testing/test_collection.py:67–94  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

65 assert pytester.collect_by_name(modcol, "doesnotexist") is None
66
67 def test_getparent_and_accessors(self, pytester: Pytester) -> None:
68 modcol = pytester.getmodulecol(
69 """
70 class TestClass:
71 def test_foo(self):
72 pass
73 """
74 )
75 cls = pytester.collect_by_name(modcol, "TestClass")
76 assert isinstance(cls, pytest.Class)
77 fn = pytester.collect_by_name(cls, "test_foo")
78 assert isinstance(fn, pytest.Function)
79
80 assert fn.getparent(pytest.Module) is modcol
81 assert modcol.module is not None
82 assert modcol.cls is None
83 assert modcol.instance is None
84
85 assert fn.getparent(pytest.Class) is cls
86 assert cls.module is not None
87 assert cls.cls is not None
88 assert cls.instance is None
89
90 assert fn.getparent(pytest.Function) is fn
91 assert fn.module is not None
92 assert fn.cls is not None
93 assert fn.instance is not None
94 assert fn.function is not None
95
96 def test_getcustomfile_roundtrip(self, pytester: Pytester) -> None:
97 hello = pytester.makefile(".xxx", hello="world")

Callers

nothing calls this directly

Calls 3

getparentMethod · 0.80
getmodulecolMethod · 0.45
collect_by_nameMethod · 0.45

Tested by

no test coverage detected