@@ -64,7 +64,7 @@ def test_fail(): assert 0
64
64
65
65
assert pytester .collect_by_name (modcol , "doesnotexist" ) is None
66
66
67
- def test_getparent (self , pytester : Pytester ) -> None :
67
+ def test_getparent_and_accessors (self , pytester : Pytester ) -> None :
68
68
modcol = pytester .getmodulecol (
69
69
"""
70
70
class TestClass:
@@ -77,14 +77,21 @@ def test_foo(self):
77
77
fn = pytester .collect_by_name (cls , "test_foo" )
78
78
assert isinstance (fn , pytest .Function )
79
79
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
88
95
89
96
def test_getcustomfile_roundtrip (self , pytester : Pytester ) -> None :
90
97
hello = pytester .makefile (".xxx" , hello = "world" )
0 commit comments