gh-71339: Fix an order-dependent failure in test_unittest (GH-129133)

It failed if it was preceded by test_builtin.
This commit is contained in:
Serhiy Storchaka 2025-01-21 16:45:20 +02:00 committed by GitHub
parent 5809b25909
commit 4b37a6bda2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View file

@ -1833,7 +1833,10 @@ class BuiltinTest(ComplexesAreIdenticalMixin, unittest.TestCase):
def test_setattr(self):
setattr(sys, 'spam', 1)
try:
self.assertEqual(sys.spam, 1)
finally:
del sys.spam
self.assertRaises(TypeError, setattr)
self.assertRaises(TypeError, setattr, sys)
self.assertRaises(TypeError, setattr, sys, 'spam')

View file

@ -801,9 +801,9 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
self.assertEqual(str(cm.exception),
"type object 'List' has no attribute 'spam'")
with self.assertRaises(self.failureException) as cm:
self.assertHasAttr(sys, 'spam')
self.assertHasAttr(sys, 'nonexistent')
self.assertEqual(str(cm.exception),
"module 'sys' has no attribute 'spam'")
"module 'sys' has no attribute 'nonexistent'")
with self.assertRaises(self.failureException) as cm:
self.assertHasAttr(a, 'y', 'ababahalamaha')