mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #32227 -- Prevented crash when setUpTestData() errors with --debug-sql.
Thanks Mariusz Felisiak for the report.
This commit is contained in:
committed by
Mariusz Felisiak
parent
7603036bd0
commit
b9fd09d21b
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user