mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #26791 -- Replaced LiveServerTestCase port ranges with binding to port 0.
This commit is contained in:
@@ -28,7 +28,6 @@ from django.db.migrations.recorder import MigrationRecorder
|
||||
from django.test import (
|
||||
LiveServerTestCase, SimpleTestCase, TestCase, mock, override_settings,
|
||||
)
|
||||
from django.test.runner import DiscoverRunner
|
||||
from django.utils._os import npath, upath
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six import PY2, PY3, StringIO
|
||||
@@ -1276,46 +1275,6 @@ class ManageCheck(AdminScriptTestCase):
|
||||
self.assertNoOutput(out)
|
||||
|
||||
|
||||
class CustomTestRunner(DiscoverRunner):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
assert 'liveserver' not in kwargs
|
||||
super(CustomTestRunner, self).__init__(*args, **kwargs)
|
||||
|
||||
def run_tests(self, test_labels, extra_tests=None, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class ManageTestCommand(AdminScriptTestCase):
|
||||
def test_liveserver(self):
|
||||
"""
|
||||
Ensure that the --liveserver option sets the environment variable
|
||||
correctly.
|
||||
Refs #2879.
|
||||
"""
|
||||
|
||||
# Backup original state
|
||||
address_predefined = 'DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ
|
||||
old_address = os.environ.get('DJANGO_LIVE_TEST_SERVER_ADDRESS')
|
||||
|
||||
call_command('test', verbosity=0, testrunner='admin_scripts.tests.CustomTestRunner')
|
||||
|
||||
# Original state hasn't changed
|
||||
self.assertEqual('DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ, address_predefined)
|
||||
self.assertEqual(os.environ.get('DJANGO_LIVE_TEST_SERVER_ADDRESS'), old_address)
|
||||
|
||||
call_command('test', verbosity=0, testrunner='admin_scripts.tests.CustomTestRunner', liveserver='blah')
|
||||
|
||||
# Variable was correctly set
|
||||
self.assertEqual(os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'], 'blah')
|
||||
|
||||
# Restore original state
|
||||
if address_predefined:
|
||||
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = old_address
|
||||
else:
|
||||
del os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS']
|
||||
|
||||
|
||||
class ManageRunserver(AdminScriptTestCase):
|
||||
def setUp(self):
|
||||
from django.core.management.commands.runserver import Command
|
||||
|
||||
Reference in New Issue
Block a user