]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-71339: Fix an order-dependent failure in test_unittest (GH-129133)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 21 Jan 2025 14:45:20 +0000 (16:45 +0200)
committerGitHub <noreply@github.com>
Tue, 21 Jan 2025 14:45:20 +0000 (16:45 +0200)
It failed if it was preceded by test_builtin.

Lib/test/test_builtin.py
Lib/test/test_unittest/test_case.py

index 73b139e405ae59420c07af006bed6570cb73fce4..913d007a126d72beb2c3a3e1068c8856475ebce0 100644 (file)
@@ -1833,7 +1833,10 @@ class BuiltinTest(ComplexesAreIdenticalMixin, unittest.TestCase):
 
     def test_setattr(self):
         setattr(sys, 'spam', 1)
-        self.assertEqual(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')
index df1381451b7ebc3d93cd0c514a42dce981c46bbb..a04af55f3fc0aedec4aadc64e35e7531096f0796 100644 (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')