diff options
| author | schlamar <marc.schlaich@gmail.com> | 2013-07-19 08:59:17 +0200 |
|---|---|---|
| committer | schlamar <marc.schlaich@gmail.com> | 2013-07-31 20:41:01 +0200 |
| commit | 741ba322a0450ea97069d546c06033394ffb23c0 (patch) | |
| tree | 2fccb753d3ac72d231befbc3f7350b52ba5215d4 /dummyserver/testcase.py | |
| parent | a43e344a60f795a516c9effd509f717ff2f2af6d (diff) | |
| download | urllib3-741ba322a0450ea97069d546c06033394ffb23c0.tar.gz | |
Allocate ports for tests automatically.
Diffstat (limited to 'dummyserver/testcase.py')
| -rw-r--r-- | dummyserver/testcase.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/dummyserver/testcase.py b/dummyserver/testcase.py index 3744f1cd..a2cd1597 100644 --- a/dummyserver/testcase.py +++ b/dummyserver/testcase.py @@ -1,5 +1,6 @@ import unittest +import socket from threading import Lock from dummyserver.server import ( @@ -9,7 +10,10 @@ from dummyserver.server import ( ) -# TODO: Change ports to auto-allocated? +def get_free_port(): + s = socket.socket() + s.bind(('127.0.0.1', 0)) + return s.getsockname()[1] class SocketDummyServerTestCase(unittest.TestCase): @@ -19,7 +23,7 @@ class SocketDummyServerTestCase(unittest.TestCase): """ scheme = 'http' host = 'localhost' - port = 18080 + port = get_free_port() @classmethod def _start_server(cls, socket_handler): @@ -43,7 +47,7 @@ class HTTPDummyServerTestCase(unittest.TestCase): scheme = 'http' host = 'localhost' host_alt = '127.0.0.1' # Some tests need two hosts - port = 18081 + port = get_free_port() certs = DEFAULT_CERTS @classmethod @@ -74,7 +78,7 @@ class HTTPDummyServerTestCase(unittest.TestCase): class HTTPSDummyServerTestCase(HTTPDummyServerTestCase): scheme = 'https' host = 'localhost' - port = 18082 + port = get_free_port() certs = DEFAULT_CERTS @@ -82,16 +86,16 @@ class HTTPDummyProxyTestCase(unittest.TestCase): http_host = 'localhost' http_host_alt = '127.0.0.1' - http_port = 18081 + http_port = get_free_port() https_host = 'localhost' - https_port = 18082 + https_port = get_free_port() https_host_alt = '127.0.0.1' https_certs = DEFAULT_CERTS proxy_host = 'localhost' proxy_host_alt = '127.0.0.1' - proxy_port = 18083 + proxy_port = get_free_port() @classmethod def setUpClass(cls): @@ -109,4 +113,3 @@ class HTTPDummyProxyTestCase(unittest.TestCase): @classmethod def tearDownClass(cls): cls.proxy_thread.stop() - |
