summaryrefslogtreecommitdiff
path: root/django/test/testcases.py
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 /django/test/testcases.py
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 'django/test/testcases.py')
-rw-r--r--django/test/testcases.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 468c0c4fbc..ca5712ee8d 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -9,6 +9,7 @@ from contextlib import contextmanager
from copy import copy
from difflib import get_close_matches
from functools import wraps
+from unittest.suite import _DebugResult
from unittest.util import safe_repr
from urllib.parse import (
parse_qsl, unquote, urlencode, urljoin, urlparse, urlsplit, urlunparse,
@@ -235,6 +236,21 @@ class SimpleTestCase(unittest.TestCase):
set up. This means that user-defined Test Cases aren't required to
include a call to super().setUp().
"""
+ self._setup_and_call(result)
+
+ def debug(self):
+ """Perform the same as __call__(), without catching the exception."""
+ debug_result = _DebugResult()
+ self._setup_and_call(debug_result, debug=True)
+
+ def _setup_and_call(self, result, debug=False):
+ """
+ Perform the following in order: pre-setup, run test, post-teardown,
+ skipping pre/post hooks if test is set to be skipped.
+
+ If debug=True, reraise any errors in setup and use super().debug()
+ instead of __call__() to run the test.
+ """
testMethod = getattr(self, self._testMethodName)
skipped = (
getattr(self.__class__, "__unittest_skip__", False) or
@@ -245,13 +261,20 @@ class SimpleTestCase(unittest.TestCase):
try:
self._pre_setup()
except Exception:
+ if debug:
+ raise
result.addError(self, sys.exc_info())
return
- super().__call__(result)
+ if debug:
+ super().debug()
+ else:
+ super().__call__(result)
if not skipped:
try:
self._post_teardown()
except Exception:
+ if debug:
+ raise
result.addError(self, sys.exc_info())
return