Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba21f61

Browse files
committed
Fix refleaks in test_with caused by reusing the same exception instance over and over.
1 parent c59dacd commit ba21f61

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/test/test_with.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ def shouldThrow():
187187
self.assertRaises(RuntimeError, shouldThrow)
188188

189189
class ContextmanagerAssertionMixin(object):
190-
TEST_EXCEPTION = RuntimeError("test exception")
190+
191+
def setUp(self):
192+
self.TEST_EXCEPTION = RuntimeError("test exception")
191193

192194
def assertInWithManagerInvariants(self, mock_manager):
193195
self.assertTrue(mock_manager.enter_called)
@@ -353,7 +355,7 @@ def testMultipleArgBound(self):
353355
self.assertAfterWithManagerInvariantsNoError(mock_nested)
354356

355357

356-
class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
358+
class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
357359
def testSingleResource(self):
358360
cm = mock_contextmanager_generator()
359361
def shouldThrow():

0 commit comments

Comments
 (0)