mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #28212 -- Allowed customizing the port that LiveServerTestCase uses.
Forwardport of 877d7b71ae
from stable/1.11.x
This commit is contained in:
parent
a30482a4b6
commit
b6d4b6e544
5 changed files with 42 additions and 7 deletions
|
@ -147,6 +147,24 @@ class LiveServerPort(LiveServerBase):
|
|||
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()
|
||||
|
||||
|
||||
class LiverServerThreadedTests(LiveServerBase):
|
||||
"""If LiverServerTestCase isn't threaded, these tests will hang."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue