|
6 | 6 |
|
7 | 7 | from __future__ import with_statement
|
8 | 8 |
|
| 9 | +import socket |
| 10 | + |
9 | 11 | import pytest
|
10 | 12 |
|
11 | 13 | from django.db import connection, transaction
|
@@ -321,18 +323,35 @@ def test_serve_static_dj17_without_staticfiles_app(self, live_server,
|
321 | 323 |
|
322 | 324 | @pytest.mark.skipif(get_django_version() < (1, 11),
|
323 | 325 | reason='Django >= 1.11 required')
|
324 |
| - def test_specified_port_error_message_django_111(self, django_testdir): |
| 326 | + def test_specified_port_range_error_message_django_111(self, django_testdir): |
325 | 327 | django_testdir.create_test_module("""
|
326 | 328 | def test_with_live_server(live_server):
|
327 | 329 | pass
|
328 | 330 | """)
|
329 | 331 |
|
330 |
| - result = django_testdir.runpytest_subprocess('--liveserver=localhost:1234') |
| 332 | + result = django_testdir.runpytest_subprocess('--liveserver=localhost:1234-2345') |
331 | 333 | result.stdout.fnmatch_lines([
|
332 |
| - '*Specifying a live server port is not supported in Django 1.11. This ' |
| 334 | + '*Specifying multiple live server ports is not supported in Django 1.11. This ' |
333 | 335 | 'will be an error in a future pytest-django release.*'
|
334 | 336 | ])
|
335 | 337 |
|
| 338 | + @pytest.mark.skipif(get_django_version() < (1, 11, 2), |
| 339 | + reason='Django >= 1.11.2 required') |
| 340 | + def test_specified_port_django_111(self, django_testdir): |
| 341 | + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 342 | + try: |
| 343 | + sock.bind(('', 0)) |
| 344 | + __, port = sock.getsockname() |
| 345 | + finally: |
| 346 | + sock.close() |
| 347 | + |
| 348 | + django_testdir.create_test_module(""" |
| 349 | + def test_with_live_server(live_server): |
| 350 | + assert live_server.port == %d |
| 351 | + """ % port) |
| 352 | + |
| 353 | + django_testdir.runpytest_subprocess('--liveserver=localhost:%s' % port) |
| 354 | + |
336 | 355 |
|
337 | 356 | @pytest.mark.django_project(extra_settings="""
|
338 | 357 | AUTH_USER_MODEL = 'app.MyCustomUser'
|
|
0 commit comments