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

Fixed #32227 -- Prevented crash when setUpTestData() errors with --debug-sql.

Thanks Mariusz Felisiak for the report.
This commit is contained in:
Adam Johnson
2020-11-26 10:07:18 +00:00
committed by Mariusz Felisiak
parent 7603036bd0
commit b9fd09d21b
2 changed files with 35 additions and 2 deletions

View File

@@ -25,6 +25,14 @@ class TestDebugSQL(unittest.TestCase):
Person.objects.filter(first_name='error').count()
raise Exception
class ErrorSetUpTestDataTest(TestCase):
@classmethod
def setUpTestData(cls):
raise Exception
def runTest(self):
pass
class PassingSubTest(TestCase):
def runTest(self):
with self.subTest():
@@ -107,3 +115,22 @@ class TestDebugSQL(unittest.TestCase):
'''FROM "test_runner_person" WHERE '''
'''"test_runner_person"."first_name" = 'subtest-pass';'''),
]
def test_setupclass_exception(self):
runner = DiscoverRunner(debug_sql=True, verbosity=0)
suite = runner.test_suite()
suite.addTest(self.ErrorSetUpTestDataTest())
old_config = runner.setup_databases()
stream = StringIO()
runner.test_runner(
verbosity=0,
stream=stream,
resultclass=runner.get_resultclass(),
).run(suite)
runner.teardown_databases(old_config)
output = stream.getvalue()
self.assertIn(
'ERROR: setUpClass '
'(test_runner.test_debug_sql.TestDebugSQL.ErrorSetUpTestDataTest)',
output,
)