mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Fixed #26791 -- Replaced LiveServerTestCase port ranges with binding to port 0.
This commit is contained in:
parent
b5a1c3a6f5
commit
81cdcb66bc
9 changed files with 32 additions and 215 deletions
|
@ -1227,12 +1227,6 @@ Stops running tests and reports the failure immediately after a test fails.
|
|||
Controls the test runner class that is used to execute tests. This value
|
||||
overrides the value provided by the :setting:`TEST_RUNNER` setting.
|
||||
|
||||
.. django-admin-option:: --liveserver LIVESERVER
|
||||
|
||||
Overrides the default address where the live server (used with
|
||||
:class:`~django.test.LiveServerTestCase`) is expected to run from. The default
|
||||
value is ``localhost:8081-8179``.
|
||||
|
||||
.. django-admin-option:: --noinput, --no-input
|
||||
|
||||
Suppresses all user prompts. A typical prompt is a warning about deleting an
|
||||
|
|
|
@ -250,6 +250,15 @@ Django 1.11 sets PostgreSQL 9.3 as the minimum version it officially supports.
|
|||
Support for PostGIS 2.0 is also removed as PostgreSQL 9.2 is the last version
|
||||
to support it.
|
||||
|
||||
``LiveServerTestCase`` binds to port zero
|
||||
-----------------------------------------
|
||||
|
||||
Rather than taking a port range and iterating to find a free port,
|
||||
``LiveServerTestCase`` binds to port zero and relies on the operating system
|
||||
to assign a free port. The ``DJANGO_LIVE_TEST_SERVER_ADDRESS`` environment
|
||||
variable is no longer used, and as it's also no longer used, the
|
||||
``manage.py test --liveserver`` option is removed.
|
||||
|
||||
Miscellaneous
|
||||
-------------
|
||||
|
||||
|
|
|
@ -814,39 +814,16 @@ 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 listens on ``localhost`` and picks the first
|
||||
available port in the ``8081-8179`` range. Its full URL can be accessed with
|
||||
The live server listens on ``localhost`` and binds to port 0 which uses a free
|
||||
port assigned by the operating system. The server's URL can be accessed with
|
||||
``self.live_server_url`` during the tests.
|
||||
|
||||
If you'd like to select another address, you may pass a different one using the
|
||||
:option:`test --liveserver` option, for example:
|
||||
.. versionchanged:: 1.11
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ ./manage.py test --liveserver=localhost:8082
|
||||
|
||||
Another way of changing the default server address is by setting the
|
||||
`DJANGO_LIVE_TEST_SERVER_ADDRESS` environment variable somewhere in your
|
||||
code (for example, in a :ref:`custom test runner<topics-testing-test_runner>`)::
|
||||
|
||||
import os
|
||||
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = 'localhost:8082'
|
||||
|
||||
In the case where the tests are run by multiple processes in parallel (for
|
||||
example, in the context of several simultaneous `continuous integration`_
|
||||
builds), the processes will compete for the same address, and therefore your
|
||||
tests might randomly fail with an "Address already in use" error. To avoid this
|
||||
problem, you can pass a comma-separated list of ports or ranges of ports (at
|
||||
least as many as the number of potential parallel processes). For example:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ ./manage.py test --liveserver=localhost:8082,8090-8100,9000-9200,7041
|
||||
|
||||
Then, during test execution, each new live test server will try every specified
|
||||
port until it finds one that is free and takes it.
|
||||
|
||||
.. _continuous integration: https://en.wikipedia.org/wiki/Continuous_integration
|
||||
In older versions, Django tried a predefined port range which could be
|
||||
customized in various ways including the ``DJANGO_LIVE_TEST_SERVER_ADDRESS``
|
||||
environment variable. This is removed in favor of the simpler "bind to port
|
||||
0" technique.
|
||||
|
||||
To demonstrate how to use ``LiveServerTestCase``, let's write a simple Selenium
|
||||
test. First of all, you need to install the `selenium package`_ into your
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue