summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2016-08-09 01:40:40 -0700
committerTim Graham <timograham@gmail.com>2016-08-09 13:40:29 -0400
commita3a5ef4d0e3bf10ff80b26dd2635e40679156a2f (patch)
treeb0d4dfb017e6546da5abded05bbf9ef5c4450220
parentac1975b18b5a33234284bec86e5a5bb44a4af976 (diff)
Fixed #27035 -- Eased changing settings.DEBUG for DiscoverRunner.
-rw-r--r--django/test/runner.py5
-rw-r--r--docs/releases/1.11.txt4
-rw-r--r--docs/topics/testing/advanced.txt11
-rw-r--r--tests/test_runner/test_discover_runner.py4
4 files changed, 20 insertions, 4 deletions
diff --git a/django/test/runner.py b/django/test/runner.py
index 537f9aa35f..179b434713 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -360,7 +360,7 @@ class DiscoverRunner(object):
def __init__(self, pattern=None, top_level=None, verbosity=1,
interactive=True, failfast=False, keepdb=False,
- reverse=False, debug_sql=False, parallel=0,
+ reverse=False, debug_mode=False, debug_sql=False, parallel=0,
tags=None, exclude_tags=None, **kwargs):
self.pattern = pattern
@@ -370,6 +370,7 @@ class DiscoverRunner(object):
self.failfast = failfast
self.keepdb = keepdb
self.reverse = reverse
+ self.debug_mode = debug_mode
self.debug_sql = debug_sql
self.parallel = parallel
self.tags = set(tags or [])
@@ -413,7 +414,7 @@ class DiscoverRunner(object):
def setup_test_environment(self, **kwargs):
setup_test_environment()
- settings.DEBUG = False
+ settings.DEBUG = self.debug_mode
unittest.installHandler()
def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt
index edf9c83dfe..4d29ad3640 100644
--- a/docs/releases/1.11.txt
+++ b/docs/releases/1.11.txt
@@ -259,6 +259,10 @@ Tests
* Added :meth:`.DiscoverRunner.get_test_runner_kwargs` to allow customizing the
keyword arguments passed to the test runner.
+* Added the ``debug_mode`` keyword argument to
+ :class:`~django.test.runner.DiscoverRunner` to make it easier to customize
+ the :setting:`DEBUG` setting when running tests.
+
URLs
~~~~
diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt
index 7127657cfc..5b09bd33f3 100644
--- a/docs/topics/testing/advanced.txt
+++ b/docs/topics/testing/advanced.txt
@@ -427,7 +427,7 @@ behavior. This class defines the ``run_tests()`` entry point, plus a
selection of other methods that are used to by ``run_tests()`` to set up,
execute and tear down the test suite.
-.. class:: DiscoverRunner(pattern='test*.py', top_level=None, verbosity=1, interactive=True, failfast=False, keepdb=False, reverse=False, debug_sql=False, **kwargs)
+.. class:: DiscoverRunner(pattern='test*.py', top_level=None, verbosity=1, interactive=True, failfast=False, keepdb=False, reverse=False, debug_mode=False, debug_sql=False, **kwargs)
``DiscoverRunner`` will search for tests in any file matching ``pattern``.
@@ -458,6 +458,9 @@ execute and tear down the test suite.
and have side effects. :ref:`Grouping by test class <order-of-tests>` is
preserved when using this option.
+ ``debug_mode`` specifies what the :setting:`DEBUG` setting should be
+ set to prior to running tests.
+
If ``debug_sql`` is ``True``, failing test cases will output SQL queries
logged to the :ref:`django.db.backends logger <django-db-logger>` as well
as the traceback. If ``verbosity`` is ``2``, then queries in all tests are
@@ -473,6 +476,10 @@ execute and tear down the test suite.
custom arguments by calling ``parser.add_argument()`` inside the method, so
that the :djadmin:`test` command will be able to use those arguments.
+ .. versionadded:: 1.11
+
+ The ``debug_mode`` keyword argument was added.
+
Attributes
~~~~~~~~~~
@@ -526,7 +533,7 @@ Methods
Sets up the test environment by calling
:func:`~django.test.utils.setup_test_environment` and setting
- :setting:`DEBUG` to ``False``.
+ :setting:`DEBUG` to ``self.debug_mode`` (defaults to ``False``).
.. method:: DiscoverRunner.build_suite(test_labels, extra_tests=None, **kwargs)
diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py
index 15f71ba1c1..0b7e18291b 100644
--- a/tests/test_runner/test_discover_runner.py
+++ b/tests/test_runner/test_discover_runner.py
@@ -20,6 +20,10 @@ def change_cwd(directory):
class DiscoverRunnerTest(TestCase):
+ def test_init_debug_mode(self):
+ runner = DiscoverRunner()
+ self.assertFalse(runner.debug_mode)
+
def test_dotted_test_module(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests_sample"],