mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #31944 -- Used addCleanup() to register TestContextDecorator cleanups.
Cleanups from addCleanup() are scheduled to happen in reverse order to the order they are added (LIFO). Ensures each cleanup is executed from the innermost to the outermost.
This commit is contained in:
committed by
Mariusz Felisiak
parent
11ebc6479f
commit
57dadfac3c
@@ -1477,4 +1477,27 @@ class TestContextDecoratorTests(SimpleTestCase):
|
||||
self.assertFalse(mock_disable.called)
|
||||
with self.assertRaisesMessage(NotImplementedError, 'reraised'):
|
||||
decorated_test_class.setUp()
|
||||
decorated_test_class.doCleanups()
|
||||
self.assertTrue(mock_disable.called)
|
||||
|
||||
def test_cleanups_run_after_tearDown(self):
|
||||
calls = []
|
||||
|
||||
class SaveCallsDecorator(TestContextDecorator):
|
||||
def enable(self):
|
||||
calls.append('enable')
|
||||
|
||||
def disable(self):
|
||||
calls.append('disable')
|
||||
|
||||
class AddCleanupInSetUp(unittest.TestCase):
|
||||
def setUp(self):
|
||||
calls.append('setUp')
|
||||
self.addCleanup(lambda: calls.append('cleanup'))
|
||||
|
||||
decorator = SaveCallsDecorator()
|
||||
decorated_test_class = decorator.__call__(AddCleanupInSetUp)()
|
||||
decorated_test_class.setUp()
|
||||
decorated_test_class.tearDown()
|
||||
decorated_test_class.doCleanups()
|
||||
self.assertEqual(calls, ['enable', 'setUp', 'cleanup', 'disable'])
|
||||
|
||||
Reference in New Issue
Block a user