mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[1.11.x] Fixed #28212 -- Allowed customizing the port that LiveServerTestCase uses.
This commit is contained in:
committed by
Tim Graham
parent
ceb6a64f2f
commit
877d7b71ae
@@ -136,3 +136,21 @@ class LiveServerPort(LiveServerBase):
|
||||
finally:
|
||||
if hasattr(TestCase, 'server_thread'):
|
||||
TestCase.server_thread.terminate()
|
||||
|
||||
def test_specified_port_bind(self):
|
||||
"""LiveServerTestCase.port customizes the server's port."""
|
||||
TestCase = type(str('TestCase'), (LiveServerBase,), {})
|
||||
# Find an open port and tell TestCase to use it.
|
||||
s = socket.socket()
|
||||
s.bind(('', 0))
|
||||
TestCase.port = s.getsockname()[1]
|
||||
s.close()
|
||||
TestCase.setUpClass()
|
||||
try:
|
||||
self.assertEqual(
|
||||
TestCase.port, TestCase.server_thread.port,
|
||||
'Did not use specified port for LiveServerTestCase thread: %s' % TestCase.port
|
||||
)
|
||||
finally:
|
||||
if hasattr(TestCase, 'server_thread'):
|
||||
TestCase.server_thread.terminate()
|
||||
|
||||
Reference in New Issue
Block a user