Skip to content

Commit d54f644

Browse files
[3.11] gh-103193: Improve getattr_static test coverage (GH-104286) (#104290)
gh-103193: Improve `getattr_static` test coverage (GH-104286) (cherry picked from commit 921185e) Co-authored-by: Alex Waygood <[email protected]>
1 parent 499b79d commit d54f644

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Lib/test/test_inspect.py

+29
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,35 @@ class Thing(metaclass=Meta):
21062106
inspect.getattr_static(Thing, "spam")
21072107
self.assertFalse(Thing.executed)
21082108

2109+
def test_custom___getattr__(self):
2110+
test = self
2111+
test.called = False
2112+
2113+
class Foo:
2114+
def __getattr__(self, attr):
2115+
test.called = True
2116+
return {}
2117+
2118+
with self.assertRaises(AttributeError):
2119+
inspect.getattr_static(Foo(), 'whatever')
2120+
2121+
self.assertFalse(test.called)
2122+
2123+
def test_custom___getattribute__(self):
2124+
test = self
2125+
test.called = False
2126+
2127+
class Foo:
2128+
def __getattribute__(self, attr):
2129+
test.called = True
2130+
return {}
2131+
2132+
with self.assertRaises(AttributeError):
2133+
inspect.getattr_static(Foo(), 'really_could_be_anything')
2134+
2135+
self.assertFalse(test.called)
2136+
2137+
21092138
class TestGetGeneratorState(unittest.TestCase):
21102139

21112140
def setUp(self):

0 commit comments

Comments
 (0)