1
0
mirror of https://github.com/django/django.git synced 2025-01-03 06:55:47 +00:00

Fixed #34111 -- Made test runner with --debug-sql format SQL queries.

This commit is contained in:
Giebisch 2022-10-21 00:37:27 +02:00 committed by Mariusz Felisiak
parent 5ec64fa481
commit 3283120cca
5 changed files with 24 additions and 16 deletions

View File

@ -17,6 +17,8 @@ from contextlib import contextmanager
from importlib import import_module from importlib import import_module
from io import StringIO from io import StringIO
import sqlparse
import django import django
from django.core.management import call_command from django.core.management import call_command
from django.db import connections from django.db import connections
@ -95,7 +97,9 @@ class DebugSQLTextTestResult(unittest.TextTestResult):
self.stream.writeln(self.separator2) self.stream.writeln(self.separator2)
self.stream.writeln(err) self.stream.writeln(err)
self.stream.writeln(self.separator2) self.stream.writeln(self.separator2)
self.stream.writeln(sql_debug) self.stream.writeln(
sqlparse.format(sql_debug, reindent=True, keyword_case="upper")
)
class PDBDebugResult(unittest.TextTestResult): class PDBDebugResult(unittest.TextTestResult):

View File

@ -294,7 +294,7 @@ dependencies:
* memcached_, plus a :ref:`supported Python binding <memcached>` * memcached_, plus a :ref:`supported Python binding <memcached>`
* gettext_ (:ref:`gettext_on_windows`) * gettext_ (:ref:`gettext_on_windows`)
* selenium_ * selenium_
* sqlparse_ 0.2.2+ (required) * sqlparse_ 0.2.3+ (required)
* tblib_ 1.5.0+ * tblib_ 1.5.0+
You can find these dependencies in `pip requirements files`_ inside the You can find these dependencies in `pip requirements files`_ inside the

View File

@ -261,7 +261,8 @@ Templates
Tests Tests
~~~~~ ~~~~~
* ... * The :option:`test --debug-sql` option now formats SQL queries with
``sqlparse``.
URLs URLs
~~~~ ~~~~
@ -338,6 +339,9 @@ Miscellaneous
* The ``alias`` argument for :meth:`.Expression.get_group_by_cols` is removed. * The ``alias`` argument for :meth:`.Expression.get_group_by_cols` is removed.
* The minimum supported version of ``sqlparse`` is increased from 0.2.2 to
0.2.3.
.. _deprecated-features-4.2: .. _deprecated-features-4.2:
Features deprecated in 4.2 Features deprecated in 4.2

View File

@ -17,7 +17,7 @@ pywatchman; sys.platform != 'win32'
PyYAML PyYAML
redis >= 3.0.0 redis >= 3.0.0
selenium selenium
sqlparse >= 0.2.2 sqlparse >= 0.2.3
tblib >= 1.5.0 tblib >= 1.5.0
tzdata tzdata
colorama; sys.platform == 'win32' colorama; sys.platform == 'win32'

View File

@ -89,24 +89,24 @@ class TestDebugSQL(unittest.TestCase):
expected_outputs = [ expected_outputs = [
( (
"""SELECT COUNT(*) AS "__count" """ """SELECT COUNT(*) AS "__count"\n"""
"""FROM "test_runner_person" WHERE """ """FROM "test_runner_person"\n"""
""""test_runner_person"."first_name" = 'error';""" """WHERE "test_runner_person"."first_name" = 'error';"""
), ),
( (
"""SELECT COUNT(*) AS "__count" """ """SELECT COUNT(*) AS "__count"\n"""
"""FROM "test_runner_person" WHERE """ """FROM "test_runner_person"\n"""
""""test_runner_person"."first_name" = 'fail';""" """WHERE "test_runner_person"."first_name" = 'fail';"""
), ),
( (
"""SELECT COUNT(*) AS "__count" """ """SELECT COUNT(*) AS "__count"\n"""
"""FROM "test_runner_person" WHERE """ """FROM "test_runner_person"\n"""
""""test_runner_person"."first_name" = 'subtest-error';""" """WHERE "test_runner_person"."first_name" = 'subtest-error';"""
), ),
( (
"""SELECT COUNT(*) AS "__count" """ """SELECT COUNT(*) AS "__count"\n"""
"""FROM "test_runner_person" WHERE """ """FROM "test_runner_person"\n"""
""""test_runner_person"."first_name" = 'subtest-fail';""" """WHERE "test_runner_person"."first_name" = 'subtest-fail';"""
), ),
] ]