1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #34210 -- Added unittest's durations option to the test runner.

This commit is contained in:
David Smith
2023-06-14 19:22:48 +01:00
committed by Mariusz Felisiak
parent 27b399d235
commit 74b5074174
8 changed files with 110 additions and 5 deletions

View File

@@ -1559,6 +1559,16 @@ tests, which allows it to print a traceback if the interpreter crashes. Pass
Outputs timings, including database setup and total run time.
.. django-admin-option:: --durations N
.. versionadded:: 5.0
Shows the N slowest test cases (N=0 for all).
.. admonition:: Python 3.12 and later
This feature is only available for Python 3.12 and later.
``testserver``
--------------

View File

@@ -476,6 +476,9 @@ Tests
* :class:`~django.test.AsyncClient` now supports the ``follow`` parameter.
* The new :option:`test --durations` option allows showing the duration of the
slowest tests on Python 3.12+.
URLs
~~~~

View File

@@ -533,7 +533,7 @@ behavior. This class defines the ``run_tests()`` entry point, plus a
selection of other methods that are used 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_mode=False, debug_sql=False, parallel=0, tags=None, exclude_tags=None, test_name_patterns=None, pdb=False, buffer=False, enable_faulthandler=True, timing=True, shuffle=False, logger=None, **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, parallel=0, tags=None, exclude_tags=None, test_name_patterns=None, pdb=False, buffer=False, enable_faulthandler=True, timing=True, shuffle=False, logger=None, durations=None, **kwargs)
``DiscoverRunner`` will search for tests in any file matching ``pattern``.
@@ -613,6 +613,10 @@ and tear down the test suite.
the console. The logger object will respect its logging level rather than
the ``verbosity``.
``durations`` will show a list of the N slowest test cases. Setting this
option to ``0`` will result in the duration for all tests being shown.
Requires Python 3.12+.
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
@@ -623,6 +627,10 @@ 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:: 5.0
The ``durations`` argument was added.
Attributes
~~~~~~~~~~