@@ -64,7 +64,7 @@ def test_fail(): assert 0
6464
6565 assert pytester .collect_by_name (modcol , "doesnotexist" ) is None
6666
67- def test_getparent (self , pytester : Pytester ) -> None :
67+ def test_getparent_and_accessors (self , pytester : Pytester ) -> None :
6868 modcol = pytester .getmodulecol (
6969 """
7070 class TestClass:
@@ -77,14 +77,21 @@ def test_foo(self):
7777 fn = pytester .collect_by_name (cls , "test_foo" )
7878 assert isinstance (fn , pytest .Function )
7979
80- module_parent = fn .getparent (pytest .Module )
81- assert module_parent is modcol
82-
83- function_parent = fn .getparent (pytest .Function )
84- assert function_parent is fn
85-
86- class_parent = fn .getparent (pytest .Class )
87- assert class_parent is cls
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
8895
8996 def test_getcustomfile_roundtrip (self , pytester : Pytester ) -> None :
9097 hello = pytester .makefile (".xxx" , hello = "world" )
0 commit comments