diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-09-10 16:12:36 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-09-10 16:12:36 +0200 |
| commit | b1a29541e5d37c03becde6c84e793766ef23395c (patch) | |
| tree | d3d04058e44a7080d3fcaa637bb3afa31ba4c3e4 /docs | |
| parent | acb833081dd3abca3bc62753103690f23fb3f0ec (diff) | |
| parent | a32206b3650c5ce18c0a06eb0eb40abc8becfa58 (diff) | |
Merge pull request #4761 from aaugustin/parallelize-tests-attempt-1
Fixed #20461 -- Allowed running tests in parallel.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/internals/contributing/writing-code/unit-tests.txt | 13 | ||||
| -rw-r--r-- | docs/ref/django-admin.txt | 48 | ||||
| -rw-r--r-- | docs/releases/1.9.txt | 23 | ||||
| -rw-r--r-- | docs/topics/testing/tools.txt | 17 |
4 files changed, 95 insertions, 6 deletions
diff --git a/docs/internals/contributing/writing-code/unit-tests.txt b/docs/internals/contributing/writing-code/unit-tests.txt index 8a097bba8c..55e3a2d5c7 100644 --- a/docs/internals/contributing/writing-code/unit-tests.txt +++ b/docs/internals/contributing/writing-code/unit-tests.txt @@ -284,3 +284,16 @@ combine this with ``--verbosity=2``, all SQL queries will be output:: .. versionadded:: 1.8 The ``--reverse`` and ``--debug-sql`` options were added. + +By default tests are run in parallel with one process per core. You can adjust +this behavior with the ``--parallel`` option:: + + $ ./runtests.py basic --parallel=1 + +You can also use the ``DJANGO_TEST_PROCESSES`` environment variable for this +purpose. + +.. versionadded:: 1.9 + + Support for running tests in parallel and the ``--parallel`` option were + added. diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 35a02eecc8..26702d7db7 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -1227,7 +1227,11 @@ provided by the :setting:`TEST_RUNNER` setting. The ``--liveserver`` option can be used to override the default address where the live server (used with :class:`~django.test.LiveServerTestCase`) is -expected to run from. The default value is ``localhost:8081``. +expected to run from. The default value is ``localhost:8081-8179``. + +.. versionchanged:: 1.9 + + In earlier versions, the default value was ``localhost:8081``. .. django-admin-option:: --keepdb @@ -1257,6 +1261,48 @@ 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. +.. django-admin-option:: --parallel + +.. versionadded:: 1.9 + +The ``--parallel`` option can be used to run tests in parallel in separate +processes. Since modern processors have multiple cores, this allows running +tests significantly faster. + +By default ``--parallel`` runs one process per core according to +:func:`multiprocessing.cpu_count()`. You can adjust the number of processes +either by providing it as the option's value, e.g. ``--parallel=4``, or by +setting the ``DJANGO_TEST_PROCESSES`` environment variable. + +Django distributes test cases — :class:`unittest.TestCase` subclasses — to +subprocesses. If there are fewer test cases than configured processes, Django +will reduce the number of processes accordingly. + +Each process gets its own database. You must ensure that different test cases +don't access the same resources. For instance, test cases that touch the +filesystem should create a temporary directory for their own use. + +This option requires the third-party ``tblib`` package to display tracebacks +correctly: + +.. code-block:: console + + $ pip install tblib + +This feature isn't available on Windows. It doesn't work with the Oracle +database backend either. + +.. warning:: + + When test parallelization is enabled and a test fails, Django may be + unable to display the exception traceback. This can make debugging + difficult. If you encounter this problem, run the affected test without + parallelization to see the traceback of the failure. + + This is a known limitation. It arises from the need to serialize objects + in order to exchange them between processes. See + :ref:`python:pickle-picklable` for details. + testserver <fixture fixture ...> -------------------------------- diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index 366e1ac934..3d256ae29d 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -125,6 +125,21 @@ degradation. .. _YUI's A-grade: https://github.com/yui/yui3/wiki/Graded-Browser-Support +Running tests in parallel +~~~~~~~~~~~~~~~~~~~~~~~~~ + +The :djadmin:`test` command now supports a :djadminopt:`--parallel` option to +run a project's tests in multiple processes in parallel. + +Each process gets its own database. You must ensure that different test cases +don't access the same resources. For instance, test cases that touch the +filesystem should create a temporary directory for their own use. + +This option is enabled by default for Django's own test suite provided: + +- the OS supports it (all but Windows) +- the database backend supports it (all the built-in backends but Oracle) + Minor features ~~~~~~~~~~~~~~ @@ -675,6 +690,11 @@ Database backend API before 1.0, but hasn't been overridden by any core backend in years and hasn't been called anywhere in Django's code or tests. +* In order to support test parallelization, you must implement the + ``DatabaseCreation._clone_test_db()`` method and set + ``DatabaseFeatures.can_clone_databases = True``. You may have to adjust + ``DatabaseCreation.get_test_db_clone_settings()``. + Default settings that were tuples are now lists ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1041,6 +1061,9 @@ Miscellaneous changed. They used to be ``(old_names, mirrors)`` tuples. Now they're just the first item, ``old_names``. +* By default :class:`~django.test.LiveServerTestCase` attempts to find an + available port in the 8081-8179 range instead of just trying port 8081. + .. _deprecated-features-1.9: Features deprecated in 1.9 diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 28a4921198..52a00b7ded 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -812,11 +812,18 @@ This allows the use of automated test clients other than the client, to execute a series of functional tests inside a browser and simulate a real user's actions. -By default the live server's address is ``'localhost:8081'`` and the full URL -can be accessed during the tests with ``self.live_server_url``. If you'd like -to change the default address (in the case, for example, where the 8081 port is -already taken) then you may pass a different one to the :djadmin:`test` command -via the :djadminopt:`--liveserver` option, for example: +By default the live server listens on ``localhost`` and picks the first +available port in the ``8081-8179`` range. Its full URL can be accessed with +``self.live_server_url`` during the tests. + +.. versionchanged:: 1.9 + + In earlier versions, the live server's default address was always + ``'localhost:8081'``. + +If you'd like to select another address then you may pass a different one to +the :djadmin:`test` command via the :djadminopt:`--liveserver` option, for +example: .. code-block:: console |
