diff options
| author | Robert Rollins <rrollins@caltech.edu> | 2017-05-22 10:16:56 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-05-30 18:49:10 -0400 |
| commit | b6d4b6e5445323c4a8a423d34c2ec9a30864ce19 (patch) | |
| tree | e1205721cfee32acc87d1e92a914cbdebe063728 /tests | |
| parent | a30482a4b6e5d13e7325238fdc902fbca7e714f4 (diff) | |
Fixed #28212 -- Allowed customizing the port that LiveServerTestCase uses.
Forwardport of 877d7b71ae952b3bc946e5187d6c23039a71614d from stable/1.11.x
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/servers/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/servers/tests.py b/tests/servers/tests.py index cb91131607..e7b263c088 100644 --- a/tests/servers/tests.py +++ b/tests/servers/tests.py @@ -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.""" |
