mirror of https://github.com/django/django.git
Fixed #34111 -- Made test runner with --debug-sql format SQL queries.
This commit is contained in:
parent
5ec64fa481
commit
3283120cca
|
@ -17,6 +17,8 @@ from contextlib import contextmanager
|
|||
from importlib import import_module
|
||||
from io import StringIO
|
||||
|
||||
import sqlparse
|
||||
|
||||
import django
|
||||
from django.core.management import call_command
|
||||
from django.db import connections
|
||||
|
@ -95,7 +97,9 @@ class DebugSQLTextTestResult(unittest.TextTestResult):
|
|||
self.stream.writeln(self.separator2)
|
||||
self.stream.writeln(err)
|
||||
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):
|
||||
|
|
|
@ -294,7 +294,7 @@ dependencies:
|
|||
* memcached_, plus a :ref:`supported Python binding <memcached>`
|
||||
* gettext_ (:ref:`gettext_on_windows`)
|
||||
* selenium_
|
||||
* sqlparse_ 0.2.2+ (required)
|
||||
* sqlparse_ 0.2.3+ (required)
|
||||
* tblib_ 1.5.0+
|
||||
|
||||
You can find these dependencies in `pip requirements files`_ inside the
|
||||
|
|
|
@ -261,7 +261,8 @@ Templates
|
|||
Tests
|
||||
~~~~~
|
||||
|
||||
* ...
|
||||
* The :option:`test --debug-sql` option now formats SQL queries with
|
||||
``sqlparse``.
|
||||
|
||||
URLs
|
||||
~~~~
|
||||
|
@ -338,6 +339,9 @@ Miscellaneous
|
|||
|
||||
* 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:
|
||||
|
||||
Features deprecated in 4.2
|
||||
|
|
|
@ -17,7 +17,7 @@ pywatchman; sys.platform != 'win32'
|
|||
PyYAML
|
||||
redis >= 3.0.0
|
||||
selenium
|
||||
sqlparse >= 0.2.2
|
||||
sqlparse >= 0.2.3
|
||||
tblib >= 1.5.0
|
||||
tzdata
|
||||
colorama; sys.platform == 'win32'
|
||||
|
|
|
@ -89,24 +89,24 @@ class TestDebugSQL(unittest.TestCase):
|
|||
|
||||
expected_outputs = [
|
||||
(
|
||||
"""SELECT COUNT(*) AS "__count" """
|
||||
"""FROM "test_runner_person" WHERE """
|
||||
""""test_runner_person"."first_name" = 'error';"""
|
||||
"""SELECT COUNT(*) AS "__count"\n"""
|
||||
"""FROM "test_runner_person"\n"""
|
||||
"""WHERE "test_runner_person"."first_name" = 'error';"""
|
||||
),
|
||||
(
|
||||
"""SELECT COUNT(*) AS "__count" """
|
||||
"""FROM "test_runner_person" WHERE """
|
||||
""""test_runner_person"."first_name" = 'fail';"""
|
||||
"""SELECT COUNT(*) AS "__count"\n"""
|
||||
"""FROM "test_runner_person"\n"""
|
||||
"""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"\n"""
|
||||
"""FROM "test_runner_person"\n"""
|
||||
"""WHERE "test_runner_person"."first_name" = 'subtest-error';"""
|
||||
),
|
||||
(
|
||||
"""SELECT COUNT(*) AS "__count" """
|
||||
"""FROM "test_runner_person" WHERE """
|
||||
""""test_runner_person"."first_name" = 'subtest-fail';"""
|
||||
"""SELECT COUNT(*) AS "__count"\n"""
|
||||
"""FROM "test_runner_person"\n"""
|
||||
"""WHERE "test_runner_person"."first_name" = 'subtest-fail';"""
|
||||
),
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue