mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
Fixed #24118 -- Added --debug-sql option for tests.
Added a --debug-sql option for tests and runtests.py which outputs the SQL logger for failing tests. When combined with --verbosity=2, it also outputs the SQL for passing tests. Thanks to Berker, Tim, Markus, Shai, Josh and Anssi for review and discussion.
This commit is contained in:
parent
68a439a18d
commit
b5c1a85b50
8 changed files with 204 additions and 16 deletions
|
|
@ -217,7 +217,7 @@ def teardown(state):
|
|||
setattr(settings, key, value)
|
||||
|
||||
|
||||
def django_tests(verbosity, interactive, failfast, keepdb, reverse, test_labels):
|
||||
def django_tests(verbosity, interactive, failfast, keepdb, reverse, test_labels, debug_sql):
|
||||
state = setup(verbosity, test_labels)
|
||||
extra_tests = []
|
||||
|
||||
|
|
@ -232,6 +232,7 @@ def django_tests(verbosity, interactive, failfast, keepdb, reverse, test_labels)
|
|||
failfast=failfast,
|
||||
keepdb=keepdb,
|
||||
reverse=reverse,
|
||||
debug_sql=debug_sql,
|
||||
)
|
||||
# Catch warnings thrown in test DB setup -- remove in Django 1.9
|
||||
with warnings.catch_warnings():
|
||||
|
|
@ -386,6 +387,9 @@ if __name__ == "__main__":
|
|||
parser.add_argument(
|
||||
'--selenium', action='store_true', dest='selenium', default=False,
|
||||
help='Run the Selenium tests as well (if Selenium is installed)')
|
||||
parser.add_argument(
|
||||
'--debug-sql', action='store_true', dest='debug_sql', default=False,
|
||||
help='Turn on the SQL query logger within tests')
|
||||
options = parser.parse_args()
|
||||
|
||||
# mock is a required dependency
|
||||
|
|
@ -421,6 +425,7 @@ if __name__ == "__main__":
|
|||
else:
|
||||
failures = django_tests(options.verbosity, options.interactive,
|
||||
options.failfast, options.keepdb,
|
||||
options.reverse, options.modules)
|
||||
options.reverse, options.modules,
|
||||
options.debug_sql)
|
||||
if failures:
|
||||
sys.exit(bool(failures))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue