Skip to content

Commit 9b00321

Browse files
committed
Test for fully qualified names
1 parent a86fde5 commit 9b00321

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Lib/test/test_exceptions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,21 +2049,24 @@ def blech(self):
20492049
self.assertEqual(obj, exc.obj)
20502050

20512051
def test_getattr_error_message(self):
2052+
def fqn(type):
2053+
return f'{type.__module__}.{type.__qualname__}'
2054+
20522055
class RaiseWithName:
20532056
def __getattr__(self, name):
20542057
raise AttributeError(name)
20552058
with self.assertRaises(AttributeError) as cm:
20562059
getattr(RaiseWithName(), "missing1")
2057-
self.assertRegex(str(cm.exception),
2058-
r"'.+\.RaiseWithName' object has no attribute 'missing1'")
2060+
self.assertEqual(str(cm.exception),
2061+
f"'{fqn(RaiseWithName)}' object has no attribute 'missing1'")
20592062

20602063
class BareRaise:
20612064
def __getattr__(self, name):
20622065
raise AttributeError
20632066
with self.assertRaises(AttributeError) as cm:
20642067
getattr(BareRaise(), "missing2")
2065-
self.assertRegex(str(cm.exception),
2066-
r"'.+\.BareRaise' object has no attribute 'missing2'")
2068+
self.assertEqual(str(cm.exception),
2069+
f"'{fqn(BareRaise)}' object has no attribute 'missing2'")
20672070

20682071
class RaiseCustom:
20692072
def __getattr__(self, name):

0 commit comments

Comments
 (0)