diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2017-07-05 10:17:16 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-05 16:56:24 -0400 |
| commit | 6de2930078d5d13894315c0a88549e6a5e71c701 (patch) | |
| tree | f9b5d7fbd4b309df756c4628bb7293e6b3ca05df /tests/test_runner/test_debug_sql.py | |
| parent | 61fd2b494a0c5c0b814e36f7032109239cdebbfc (diff) | |
Fixed #28360 -- Fixed test runner crash with --debug-sql on fail/error in subTest.
Diffstat (limited to 'tests/test_runner/test_debug_sql.py')
| -rw-r--r-- | tests/test_runner/test_debug_sql.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_runner/test_debug_sql.py b/tests/test_runner/test_debug_sql.py index 1b36fbc876..2ac7203051 100644 --- a/tests/test_runner/test_debug_sql.py +++ b/tests/test_runner/test_debug_sql.py @@ -26,12 +26,32 @@ class TestDebugSQL(unittest.TestCase): Person.objects.filter(first_name='error').count() raise Exception + class PassingSubTest(TestCase): + def runTest(self): + with self.subTest(): + Person.objects.filter(first_name='subtest-pass').count() + + class FailingSubTest(TestCase): + def runTest(self): + with self.subTest(): + Person.objects.filter(first_name='subtest-fail').count() + self.fail() + + class ErrorSubTest(TestCase): + def runTest(self): + with self.subTest(): + Person.objects.filter(first_name='subtest-error').count() + raise Exception + def _test_output(self, verbosity): runner = DiscoverRunner(debug_sql=True, verbosity=0) suite = runner.test_suite() suite.addTest(self.FailingTest()) suite.addTest(self.ErrorTest()) suite.addTest(self.PassingTest()) + suite.addTest(self.PassingSubTest()) + suite.addTest(self.FailingSubTest()) + suite.addTest(self.ErrorSubTest()) old_config = runner.setup_databases() stream = StringIO() resultclass = runner.get_resultclass() @@ -65,6 +85,12 @@ class TestDebugSQL(unittest.TestCase): ('''SELECT COUNT(*) AS "__count" ''' '''FROM "test_runner_person" WHERE ''' '''"test_runner_person"."first_name" = 'fail';'''), + ('''SELECT COUNT(*) AS "__count" ''' + '''FROM "test_runner_person" WHERE ''' + '''"test_runner_person"."first_name" = 'subtest-error';'''), + ('''SELECT COUNT(*) AS "__count" ''' + '''FROM "test_runner_person" WHERE ''' + '''"test_runner_person"."first_name" = 'subtest-fail';'''), ] verbose_expected_outputs = [ @@ -73,9 +99,17 @@ class TestDebugSQL(unittest.TestCase): 'runTest (test_runner.test_debug_sql.{}FailingTest) ... FAIL', 'runTest (test_runner.test_debug_sql.{}ErrorTest) ... ERROR', 'runTest (test_runner.test_debug_sql.{}PassingTest) ... ok', + 'runTest (test_runner.test_debug_sql.{}PassingSubTest) ... ok', + # If there are errors/failures in subtests but not in test itself, + # the status is not written. That behavior comes from Python. + 'runTest (test_runner.test_debug_sql.{}FailingSubTest) ...', + 'runTest (test_runner.test_debug_sql.{}ErrorSubTest) ...', ] ] + [ ('''SELECT COUNT(*) AS "__count" ''' '''FROM "test_runner_person" WHERE ''' '''"test_runner_person"."first_name" = 'pass';'''), + ('''SELECT COUNT(*) AS "__count" ''' + '''FROM "test_runner_person" WHERE ''' + '''"test_runner_person"."first_name" = 'subtest-pass';'''), ] |
