Skip to content

Commit

Permalink
gh-71339: Fix an order-dependent failure in test_unittest (GH-129133)
Browse files Browse the repository at this point in the history
It failed if it was preceded by test_builtin.
  • Loading branch information
serhiy-storchaka authored Jan 21, 2025
1 parent 5809b25 commit 4b37a6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,10 @@ def test_bug_27936(self):

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')
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_unittest/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,9 @@ def testAssertHasAttr(self):
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')
Expand Down

0 comments on commit 4b37a6b

Please sign in to comment.