Fixed #27008 -- Added --debug-mode option to DiscoverRunner.
This commit is contained in:
parent
9556005425
commit
5890b1613c
|
@ -393,6 +393,10 @@ class DiscoverRunner(object):
|
||||||
'-r', '--reverse', action='store_true', dest='reverse', default=False,
|
'-r', '--reverse', action='store_true', dest='reverse', default=False,
|
||||||
help='Reverses test cases order.',
|
help='Reverses test cases order.',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--debug-mode', action='store_true', dest='debug_mode', default=False,
|
||||||
|
help='Sets settings.DEBUG to True.',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--debug-sql', action='store_true', dest='debug_sql', default=False,
|
'-d', '--debug-sql', action='store_true', dest='debug_sql', default=False,
|
||||||
help='Prints logged SQL queries on failure.',
|
help='Prints logged SQL queries on failure.',
|
||||||
|
|
|
@ -1254,6 +1254,13 @@ Sorts test cases in the opposite execution order. This may help in debugging
|
||||||
the side effects of tests that aren't properly isolated. :ref:`Grouping by test
|
the side effects of tests that aren't properly isolated. :ref:`Grouping by test
|
||||||
class <order-of-tests>` is preserved when using this option.
|
class <order-of-tests>` is preserved when using this option.
|
||||||
|
|
||||||
|
.. django-admin-option:: --debug-mode
|
||||||
|
|
||||||
|
.. versionadded:: 1.11
|
||||||
|
|
||||||
|
Sets the :setting:`DEBUG` setting to ``True`` prior to running tests. This may
|
||||||
|
help troubleshoot test failures.
|
||||||
|
|
||||||
.. django-admin-option:: --debug-sql, -d
|
.. django-admin-option:: --debug-sql, -d
|
||||||
|
|
||||||
Enables :ref:`SQL logging <django-db-logger>` for failing tests. If
|
Enables :ref:`SQL logging <django-db-logger>` for failing tests. If
|
||||||
|
|
|
@ -269,9 +269,8 @@ Tests
|
||||||
* Added :meth:`.DiscoverRunner.get_test_runner_kwargs` to allow customizing the
|
* Added :meth:`.DiscoverRunner.get_test_runner_kwargs` to allow customizing the
|
||||||
keyword arguments passed to the test runner.
|
keyword arguments passed to the test runner.
|
||||||
|
|
||||||
* Added the ``debug_mode`` keyword argument to
|
* Added the :option:`test --debug-mode` option to help troubleshoot test
|
||||||
:class:`~django.test.runner.DiscoverRunner` to make it easier to customize
|
test failures by setting the :setting:`DEBUG` setting to ``True``.
|
||||||
the :setting:`DEBUG` setting when running tests.
|
|
||||||
|
|
||||||
URLs
|
URLs
|
||||||
~~~~
|
~~~~
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
from argparse import ArgumentParser
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from unittest import TestSuite, TextTestRunner, defaultTestLoader
|
from unittest import TestSuite, TextTestRunner, defaultTestLoader
|
||||||
|
|
||||||
|
@ -24,6 +25,15 @@ class DiscoverRunnerTest(TestCase):
|
||||||
runner = DiscoverRunner()
|
runner = DiscoverRunner()
|
||||||
self.assertFalse(runner.debug_mode)
|
self.assertFalse(runner.debug_mode)
|
||||||
|
|
||||||
|
def test_add_arguments_debug_mode(self):
|
||||||
|
parser = ArgumentParser()
|
||||||
|
DiscoverRunner.add_arguments(parser)
|
||||||
|
|
||||||
|
ns = parser.parse_args([])
|
||||||
|
self.assertFalse(ns.debug_mode)
|
||||||
|
ns = parser.parse_args(["--debug-mode"])
|
||||||
|
self.assertTrue(ns.debug_mode)
|
||||||
|
|
||||||
def test_dotted_test_module(self):
|
def test_dotted_test_module(self):
|
||||||
count = DiscoverRunner().build_suite(
|
count = DiscoverRunner().build_suite(
|
||||||
["test_discovery_sample.tests_sample"],
|
["test_discovery_sample.tests_sample"],
|
||||||
|
|
Loading…
Reference in New Issue