diff options
| author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2015-01-10 22:52:59 +0000 |
|---|---|---|
| committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2015-01-12 08:16:08 +0000 |
| commit | b5c1a85b50c709770b8e98aeecfeb8e81ca29dcf (patch) | |
| tree | 6291a3d178695605e808f4fa75b56e2553681f48 /docs | |
| parent | 68a439a18da17a65555832eff0a7c2090655b583 (diff) | |
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.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/internals/contributing/writing-code/unit-tests.txt | 18 | ||||
| -rw-r--r-- | docs/ref/django-admin.txt | 8 | ||||
| -rw-r--r-- | docs/releases/1.8.txt | 5 | ||||
| -rw-r--r-- | docs/topics/logging.txt | 2 | ||||
| -rw-r--r-- | docs/topics/testing/advanced.txt | 9 |
5 files changed, 33 insertions, 9 deletions
diff --git a/docs/internals/contributing/writing-code/unit-tests.txt b/docs/internals/contributing/writing-code/unit-tests.txt index 6067e9635d..df50a636b8 100644 --- a/docs/internals/contributing/writing-code/unit-tests.txt +++ b/docs/internals/contributing/writing-code/unit-tests.txt @@ -286,7 +286,7 @@ For example, suppose that the failing test that works on its own is .. code-block:: bash - $ ./runtests.py --bisect basic.tests.ModelTest.test_eq + $ ./runtests.py --bisect basic.tests.ModelTest.test_eq will try to determine a test that interferes with the given one. First, the test is run with the first half of the test suite. If a failure occurs, the @@ -302,7 +302,7 @@ failure. So: .. code-block:: bash - $ ./runtests.py --pair basic.tests.ModelTest.test_eq + $ ./runtests.py --pair basic.tests.ModelTest.test_eq will pair ``test_eq`` with every test label. @@ -313,7 +313,7 @@ the first one: .. code-block:: bash - $ ./runtests.py --pair basic.tests.ModelTest.test_eq queries transactions + $ ./runtests.py --pair basic.tests.ModelTest.test_eq queries transactions You can also try running any set of tests in reverse using the ``--reverse`` option in order to verify that executing tests in a different order does not @@ -321,8 +321,16 @@ cause any trouble: .. code-block:: bash - $ ./runtests.py basic --reverse + $ ./runtests.py basic --reverse + +If you wish to examine the SQL being run in failing tests, you can turn on +:ref:`SQL logging <django-db-logger>` using the ``--debug-sql`` option. If you +combine this with ``--verbosity=2``, all SQL queries will be output. + +.. code-block:: bash + + $ ./runtests.py basic --debug-sql .. versionadded:: 1.8 - The ``--reverse`` option was added. + The ``--reverse`` and ``--debug-sql`` options were added. diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index de556b28b7..570766f18d 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -1449,6 +1449,14 @@ This may help in debugging tests that aren't properly isolated and have side effects. :ref:`Grouping by test class <order-of-tests>` is preserved when using this option. +.. django-admin-option:: --debug-sql + +.. versionadded:: 1.8 + +The ``--debug-sql`` option can be used to enable :ref:`SQL logging +<django-db-logger>` for failing tests. If :djadminopt:`--verbosity` is ``2``, +then queries in passing tests are also output. + testserver <fixture fixture ...> -------------------------------- diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index dc0ce839bb..c4e4e34894 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -625,8 +625,9 @@ Tests allows you to test that two JSON fragments are not equal. * Added options to the :djadmin:`test` command to preserve the test database - (:djadminopt:`--keepdb`) and to run the test cases in reverse order - (:djadminopt:`--reverse`). + (:djadminopt:`--keepdb`), to run the test cases in reverse order + (:djadminopt:`--reverse`), and to enable SQL logging for failing tests + (:djadminopt:`--debug-sql`). * Added the :attr:`~django.test.Response.resolver_match` attribute to test client responses. diff --git a/docs/topics/logging.txt b/docs/topics/logging.txt index a1ed176da8..5dbd01c383 100644 --- a/docs/topics/logging.txt +++ b/docs/topics/logging.txt @@ -439,6 +439,8 @@ Messages to this logger have the following extra context: * ``request``: The request object that generated the logging message. +.. _django-db-logger: + ``django.db.backends`` ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt index 7865056e31..c995d5ec5c 100644 --- a/docs/topics/testing/advanced.txt +++ b/docs/topics/testing/advanced.txt @@ -355,7 +355,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=True, keepdb=False, reverse=False, **kwargs) +.. class:: DiscoverRunner(pattern='test*.py', top_level=None, verbosity=1, interactive=True, failfast=True, keepdb=False, reverse=False, debug_sql=False, **kwargs) ``DiscoverRunner`` will search for tests in any file matching ``pattern``. @@ -386,6 +386,11 @@ 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. + 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 + output. + Django may, from time to time, extend the capabilities of the test runner by adding new arguments. The ``**kwargs`` declaration allows for this expansion. If you subclass ``DiscoverRunner`` or write your own test @@ -402,7 +407,7 @@ execute and tear down the test suite. subclassed test runner to add options to the list of command-line options that the :djadmin:`test` command could use. - The ``keepdb`` and the ``reverse`` arguments were added. + The ``keepdb``, ``reverse``, and ``debug_sql`` arguments were added. Attributes ~~~~~~~~~~ |
