1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #29866 -- Made DiscoverRunner do tests tear down if running checks or tests raises an exception.

This commit is contained in:
Jayden Kneller
2018-10-18 17:04:28 -06:00
committed by Tim Graham
parent 630f3d8b46
commit 916aecd29d
2 changed files with 73 additions and 4 deletions

View File

@@ -602,10 +602,22 @@ class DiscoverRunner:
self.setup_test_environment()
suite = self.build_suite(test_labels, extra_tests)
old_config = self.setup_databases()
self.run_checks()
result = self.run_suite(suite)
self.teardown_databases(old_config)
self.teardown_test_environment()
run_failed = False
try:
self.run_checks()
result = self.run_suite(suite)
except Exception:
run_failed = True
raise
finally:
try:
self.teardown_databases(old_config)
self.teardown_test_environment()
except Exception:
# Silence teardown exceptions if an exception was raised during
# runs to avoid shadowing it.
if not run_failed:
raise
return self.suite_result(suite, result)