Skip to content

Commit 4b37a6b

Browse files
pythongh-71339: Fix an order-dependent failure in test_unittest (pythonGH-129133)
It failed if it was preceded by test_builtin.
1 parent 5809b25 commit 4b37a6b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Lib/test/test_builtin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,10 @@ def test_bug_27936(self):
18331833

18341834
def test_setattr(self):
18351835
setattr(sys, 'spam', 1)
1836-
self.assertEqual(sys.spam, 1)
1836+
try:
1837+
self.assertEqual(sys.spam, 1)
1838+
finally:
1839+
del sys.spam
18371840
self.assertRaises(TypeError, setattr)
18381841
self.assertRaises(TypeError, setattr, sys)
18391842
self.assertRaises(TypeError, setattr, sys, 'spam')

Lib/test/test_unittest/test_case.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,9 @@ def testAssertHasAttr(self):
801801
self.assertEqual(str(cm.exception),
802802
"type object 'List' has no attribute 'spam'")
803803
with self.assertRaises(self.failureException) as cm:
804-
self.assertHasAttr(sys, 'spam')
804+
self.assertHasAttr(sys, 'nonexistent')
805805
self.assertEqual(str(cm.exception),
806-
"module 'sys' has no attribute 'spam'")
806+
"module 'sys' has no attribute 'nonexistent'")
807807

808808
with self.assertRaises(self.failureException) as cm:
809809
self.assertHasAttr(a, 'y', 'ababahalamaha')

0 commit comments

Comments
 (0)