summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPavel Savchenko <asfaltboy@gmail.com>2016-10-26 23:10:17 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-18 12:22:51 +0200
commit1711c509faf3111bdf5a3a860b2cd01c0dc5d233 (patch)
tree84354e38d069e4ce0132288f9bbb0305d7934c4a /tests
parentdc8cd2fefd028913e3273927342374f5259cc566 (diff)
Fixed #27391 -- Implemented SimpleTestCase.debug().
debug() should bubbled up exceptions if occurring in test, but behave the same as run() when no exceptions occurred.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_utils/test_simpletestcase.py61
1 files changed, 58 insertions, 3 deletions
diff --git a/tests/test_utils/test_simpletestcase.py b/tests/test_utils/test_simpletestcase.py
index eb1e0017d2..76ec37e80f 100644
--- a/tests/test_utils/test_simpletestcase.py
+++ b/tests/test_utils/test_simpletestcase.py
@@ -25,6 +25,11 @@ class DebugInvocationTests(SimpleTestCase):
def get_runner(self):
return unittest.TextTestRunner(stream=StringIO())
+ def isolate_debug_test(self, test_suite, result):
+ # Suite teardown needs to be manually called to isolate failures.
+ test_suite._tearDownPreviousClass(None, result)
+ test_suite._handleModuleTearDown(result)
+
def test_run_cleanup(self, _pre_setup, _post_teardown):
"""Simple test run: catches errors and runs cleanup."""
test_suite = unittest.TestSuite()
@@ -76,6 +81,58 @@ class DebugInvocationTests(SimpleTestCase):
self.assertFalse(_post_teardown.called)
self.assertFalse(_pre_setup.called)
+ def test_debug_cleanup(self, _pre_setup, _post_teardown):
+ """Simple debug run without errors."""
+ test_suite = unittest.TestSuite()
+ test_suite.addTest(ErrorTestCase('simple_test'))
+ test_suite.debug()
+ _pre_setup.assert_called_once_with()
+ _post_teardown.assert_called_once_with()
+
+ def test_debug_bubbles_error(self, _pre_setup, _post_teardown):
+ """debug() bubbles up exceptions before cleanup."""
+ test_suite = unittest.TestSuite()
+ test_suite.addTest(ErrorTestCase('raising_test'))
+ msg = 'debug() bubbles up exceptions before cleanup.'
+ with self.assertRaisesMessage(Exception, msg):
+ # This is the same as test_suite.debug().
+ result = _DebugResult()
+ test_suite.run(result, debug=True)
+ # pre-setup is called but not post-teardown.
+ _pre_setup.assert_called_once_with()
+ self.assertFalse(_post_teardown.called)
+ self.isolate_debug_test(test_suite, result)
+
+ def test_debug_bubbles_pre_setup_error(self, _pre_setup, _post_teardown):
+ """debug() bubbles up exceptions during _pre_setup."""
+ msg = 'Exception in _pre_setup.'
+ _pre_setup.side_effect = Exception(msg)
+ test_suite = unittest.TestSuite()
+ test_suite.addTest(ErrorTestCase('simple_test'))
+ with self.assertRaisesMessage(Exception, msg):
+ # This is the same as test_suite.debug().
+ result = _DebugResult()
+ test_suite.run(result, debug=True)
+ # pre-setup is called but not post-teardown.
+ _pre_setup.assert_called_once_with()
+ self.assertFalse(_post_teardown.called)
+ self.isolate_debug_test(test_suite, result)
+
+ def test_debug_bubbles_post_teardown_error(self, _pre_setup, _post_teardown):
+ """debug() bubbles up exceptions during _post_teardown."""
+ msg = 'Exception in _post_teardown.'
+ _post_teardown.side_effect = Exception(msg)
+ test_suite = unittest.TestSuite()
+ test_suite.addTest(ErrorTestCase('simple_test'))
+ with self.assertRaisesMessage(Exception, msg):
+ # This is the same as test_suite.debug().
+ result = _DebugResult()
+ test_suite.run(result, debug=True)
+ # pre-setup and post-teardwn are called.
+ _pre_setup.assert_called_once_with()
+ _post_teardown.assert_called_once_with()
+ self.isolate_debug_test(test_suite, result)
+
def test_debug_skipped_test_no_cleanup(self, _pre_setup, _post_teardown):
test_suite = unittest.TestSuite()
test_suite.addTest(ErrorTestCase('skipped_test'))
@@ -85,6 +142,4 @@ class DebugInvocationTests(SimpleTestCase):
test_suite.run(result, debug=True)
self.assertFalse(_post_teardown.called)
self.assertFalse(_pre_setup.called)
- # Suite teardown needs to be manually called to isolate failure.
- test_suite._tearDownPreviousClass(None, result)
- test_suite._handleModuleTearDown(result)
+ self.isolate_debug_test(test_suite, result)