From 63f1758f28e623c836624025099f0dd82741c360 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 24 Dec 2023 13:29:06 +0200 Subject: [PATCH] Allow running tests in parallel (don't reuse addresses) --- tests/lib/clients/01-asyncio.py | 4 +- tests/lib/clients/01-decorators.py | 4 +- tests/lib/clients/01-keepalive-pingreq.py | 4 +- tests/lib/clients/01-no-clean-session.py | 4 +- tests/lib/clients/01-reconnect-on-failure.py | 4 +- .../clients/01-unpwd-empty-password-set.py | 4 +- tests/lib/clients/01-unpwd-empty-set.py | 4 +- tests/lib/clients/01-unpwd-set.py | 4 +- tests/lib/clients/01-unpwd-unicode-set.py | 4 +- tests/lib/clients/01-will-set.py | 4 +- tests/lib/clients/01-will-unpwd-set.py | 4 +- tests/lib/clients/01-zero-length-clientid.py | 4 +- tests/lib/clients/02-subscribe-qos0.py | 4 +- tests/lib/clients/02-subscribe-qos1.py | 4 +- tests/lib/clients/02-subscribe-qos2.py | 4 +- tests/lib/clients/02-unsubscribe.py | 4 +- tests/lib/clients/03-publish-b2c-qos1.py | 4 +- tests/lib/clients/03-publish-b2c-qos2.py | 4 +- .../clients/03-publish-c2b-qos1-disconnect.py | 4 +- .../clients/03-publish-c2b-qos2-disconnect.py | 4 +- .../lib/clients/03-publish-helper-qos0-v5.py | 4 +- tests/lib/clients/03-publish-helper-qos0.py | 4 +- .../03-publish-helper-qos1-disconnect.py | 4 +- .../lib/clients/03-publish-qos0-no-payload.py | 4 +- tests/lib/clients/03-publish-qos0.py | 4 +- tests/lib/clients/04-retain-qos0.py | 4 +- .../clients/08-ssl-connect-cert-auth-pw.py | 4 +- tests/lib/clients/08-ssl-connect-cert-auth.py | 4 +- tests/lib/clients/08-ssl-connect-no-auth.py | 4 +- tests/lib/clients/08-ssl-fake-cacert.py | 4 +- tests/lib/conftest.py | 11 ++-- tests/lib/test_01_keepalive_pingreq.py | 2 +- tests/lib/test_01_no_clean_session.py | 2 +- tests/lib/test_01_unpwd_empty_password_set.py | 2 +- tests/lib/test_01_unpwd_empty_set.py | 2 +- tests/lib/test_01_unpwd_set.py | 2 +- tests/lib/test_01_unpwd_unicode_set.py | 2 +- tests/lib/test_01_will_set.py | 2 +- tests/lib/test_01_will_unpwd_set.py | 2 +- tests/lib/test_02_subscribe_qos0.py | 2 +- tests/lib/test_02_subscribe_qos1.py | 2 +- tests/lib/test_02_subscribe_qos2.py | 2 +- tests/lib/test_03_publish_b2c_qos1.py | 2 +- tests/lib/test_03_publish_helper_qos0.py | 2 +- tests/lib/test_03_publish_helper_qos0_v5.py | 2 +- tests/lib/test_03_publish_qos0.py | 2 +- tests/lib/test_03_publish_qos0_no_payload.py | 2 +- tests/lib/test_08_ssl_connect_cert_auth.py | 2 +- tests/lib/test_08_ssl_connect_cert_auth_pw.py | 2 +- tests/lib/test_08_ssl_connect_no_auth.py | 2 +- tests/paho_test.py | 53 +++++++++---------- tests/test_client.py | 12 ++--- tests/test_websocket_integration.py | 12 ++--- tests/testsupport/broker.py | 10 ++-- 54 files changed, 128 insertions(+), 128 deletions(-) diff --git a/tests/lib/clients/01-asyncio.py b/tests/lib/clients/01-asyncio.py index 30375ffe..05f3cf55 100644 --- a/tests/lib/clients/01-asyncio.py +++ b/tests/lib/clients/01-asyncio.py @@ -3,6 +3,8 @@ import paho.mqtt.client as mqtt +from tests.paho_test import get_test_server_port + client_id = 'asyncio-test' @@ -78,7 +80,7 @@ def on_disconnect(client, userdata, rc): aioh = AsyncioHelper(loop, client) - client.connect('localhost', 1888, 60) + client.connect('localhost', get_test_server_port(), 60) client.socket().setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2048) await disconnected diff --git a/tests/lib/clients/01-decorators.py b/tests/lib/clients/01-decorators.py index ffb3cf24..03d1a32a 100644 --- a/tests/lib/clients/01-decorators.py +++ b/tests/lib/clients/01-decorators.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt mqttc = mqtt.Client("decorators-test", clean_session=True) payload = b"" @@ -38,5 +38,5 @@ def on_disconnect(mqttc, obj, rc): obj = rc -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-keepalive-pingreq.py b/tests/lib/clients/01-keepalive-pingreq.py index ec0c9573..e6ab8545 100644 --- a/tests/lib/clients/01-keepalive-pingreq.py +++ b/tests/lib/clients/01-keepalive-pingreq.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -10,5 +10,5 @@ def on_connect(mqttc, obj, flags, rc): mqttc = mqtt.Client("01-keepalive-pingreq") mqttc.on_connect = on_connect -mqttc.connect("localhost", 1888, keepalive=4) +mqttc.connect("localhost", get_test_server_port(), keepalive=4) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-no-clean-session.py b/tests/lib/clients/01-no-clean-session.py index c8ed09c5..a620ef99 100644 --- a/tests/lib/clients/01-no-clean-session.py +++ b/tests/lib/clients/01-no-clean-session.py @@ -1,8 +1,8 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt mqttc = mqtt.Client("01-no-clean-session", clean_session=False) -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-reconnect-on-failure.py b/tests/lib/clients/01-reconnect-on-failure.py index 0cb88bee..afbd3b77 100644 --- a/tests/lib/clients/01-reconnect-on-failure.py +++ b/tests/lib/clients/01-reconnect-on-failure.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import wait_for_keyboard_interrupt +from tests.paho_test import get_test_server_port, wait_for_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -11,6 +11,6 @@ def on_connect(mqttc, obj, flags, rc): mqttc.on_connect = on_connect with wait_for_keyboard_interrupt(): - mqttc.connect("localhost", 1888) + mqttc.connect("localhost", get_test_server_port()) mqttc.loop_forever() exit(42) # this is expected by the test case diff --git a/tests/lib/clients/01-unpwd-empty-password-set.py b/tests/lib/clients/01-unpwd-empty-password-set.py index c22083eb..c1115800 100644 --- a/tests/lib/clients/01-unpwd-empty-password-set.py +++ b/tests/lib/clients/01-unpwd-empty-password-set.py @@ -1,9 +1,9 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt mqttc = mqtt.Client("01-unpwd-set") mqttc.username_pw_set("uname", "") -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-unpwd-empty-set.py b/tests/lib/clients/01-unpwd-empty-set.py index 1a5284a3..300c18a1 100644 --- a/tests/lib/clients/01-unpwd-empty-set.py +++ b/tests/lib/clients/01-unpwd-empty-set.py @@ -1,9 +1,9 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt mqttc = mqtt.Client("01-unpwd-set") mqttc.username_pw_set("", "") -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-unpwd-set.py b/tests/lib/clients/01-unpwd-set.py index e34db561..a872a28c 100644 --- a/tests/lib/clients/01-unpwd-set.py +++ b/tests/lib/clients/01-unpwd-set.py @@ -1,9 +1,9 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt mqttc = mqtt.Client("01-unpwd-set") mqttc.username_pw_set("uname", ";'[08gn=#") -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-unpwd-unicode-set.py b/tests/lib/clients/01-unpwd-unicode-set.py index c3ffc40e..707ea787 100644 --- a/tests/lib/clients/01-unpwd-unicode-set.py +++ b/tests/lib/clients/01-unpwd-unicode-set.py @@ -2,12 +2,12 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt mqttc = mqtt.Client("01-unpwd-unicode-set") username = "\u00fas\u00e9rn\u00e1m\u00e9-h\u00e9ll\u00f3" password = "h\u00e9ll\u00f3" mqttc.username_pw_set(username, password) -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-will-set.py b/tests/lib/clients/01-will-set.py index 5a1f76d1..b273da32 100644 --- a/tests/lib/clients/01-will-set.py +++ b/tests/lib/clients/01-will-set.py @@ -1,9 +1,9 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt mqttc = mqtt.Client("01-will-set") mqttc.will_set("topic/on/unexpected/disconnect", "will message", 1, True) -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-will-unpwd-set.py b/tests/lib/clients/01-will-unpwd-set.py index c88adc08..3510716e 100644 --- a/tests/lib/clients/01-will-unpwd-set.py +++ b/tests/lib/clients/01-will-unpwd-set.py @@ -1,10 +1,10 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt mqttc = mqtt.Client("01-will-unpwd-set") mqttc.username_pw_set("oibvvwqw", "#'^2hg9a&nm38*us") mqttc.will_set("will-topic", "will message", 2, False) -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/01-zero-length-clientid.py b/tests/lib/clients/01-zero-length-clientid.py index b1809733..672628ad 100644 --- a/tests/lib/clients/01-zero-length-clientid.py +++ b/tests/lib/clients/01-zero-length-clientid.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -17,5 +17,5 @@ def on_disconnect(mqttc, obj, rc): mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/02-subscribe-qos0.py b/tests/lib/clients/02-subscribe-qos0.py index f5411d9d..b55fb54f 100644 --- a/tests/lib/clients/02-subscribe-qos0.py +++ b/tests/lib/clients/02-subscribe-qos0.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -21,5 +21,5 @@ def on_subscribe(mqttc, obj, mid, granted_qos): mqttc.on_disconnect = on_disconnect mqttc.on_subscribe = on_subscribe -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/02-subscribe-qos1.py b/tests/lib/clients/02-subscribe-qos1.py index 27792aa3..063eee90 100644 --- a/tests/lib/clients/02-subscribe-qos1.py +++ b/tests/lib/clients/02-subscribe-qos1.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -21,5 +21,5 @@ def on_subscribe(mqttc, obj, mid, granted_qos): mqttc.on_disconnect = on_disconnect mqttc.on_subscribe = on_subscribe -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/02-subscribe-qos2.py b/tests/lib/clients/02-subscribe-qos2.py index 45225b24..47a9e159 100644 --- a/tests/lib/clients/02-subscribe-qos2.py +++ b/tests/lib/clients/02-subscribe-qos2.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -21,5 +21,5 @@ def on_subscribe(mqttc, obj, mid, granted_qos): mqttc.on_disconnect = on_disconnect mqttc.on_subscribe = on_subscribe -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/02-unsubscribe.py b/tests/lib/clients/02-unsubscribe.py index aa178bd8..2ed5c9b8 100644 --- a/tests/lib/clients/02-unsubscribe.py +++ b/tests/lib/clients/02-unsubscribe.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -21,5 +21,5 @@ def on_unsubscribe(mqttc, obj, mid): mqttc.on_disconnect = on_disconnect mqttc.on_unsubscribe = on_unsubscribe -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/03-publish-b2c-qos1.py b/tests/lib/clients/03-publish-b2c-qos1.py index d2fe7ae4..9efc928d 100644 --- a/tests/lib/clients/03-publish-b2c-qos1.py +++ b/tests/lib/clients/03-publish-b2c-qos1.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt expected_payload = b"message" @@ -21,5 +21,5 @@ def on_connect(mqttc, obj, flags, rc): mqttc.on_connect = on_connect mqttc.on_message = on_message -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/03-publish-b2c-qos2.py b/tests/lib/clients/03-publish-b2c-qos2.py index ba871a7f..246cb097 100644 --- a/tests/lib/clients/03-publish-b2c-qos2.py +++ b/tests/lib/clients/03-publish-b2c-qos2.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import wait_for_keyboard_interrupt +from tests.paho_test import get_test_server_port, wait_for_keyboard_interrupt expected_payload = b"message" @@ -21,7 +21,7 @@ def on_connect(mqttc, obj, flags, rc): mqttc.on_connect = on_connect mqttc.on_message = on_message -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) with wait_for_keyboard_interrupt(): while True: diff --git a/tests/lib/clients/03-publish-c2b-qos1-disconnect.py b/tests/lib/clients/03-publish-c2b-qos1-disconnect.py index 8d958d36..17a0df3d 100644 --- a/tests/lib/clients/03-publish-c2b-qos1-disconnect.py +++ b/tests/lib/clients/03-publish-c2b-qos1-disconnect.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt sent_mid = -1 @@ -29,5 +29,5 @@ def on_publish(mqttc, obj, mid): mqttc.on_disconnect = on_disconnect mqttc.on_publish = on_publish -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/03-publish-c2b-qos2-disconnect.py b/tests/lib/clients/03-publish-c2b-qos2-disconnect.py index cc66a0e4..6e0fddfe 100644 --- a/tests/lib/clients/03-publish-c2b-qos2-disconnect.py +++ b/tests/lib/clients/03-publish-c2b-qos2-disconnect.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt first_connection = 1 @@ -27,5 +27,5 @@ def on_publish(mqttc, obj, mid): mqttc.on_disconnect = on_disconnect mqttc.on_publish = on_publish -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/03-publish-helper-qos0-v5.py b/tests/lib/clients/03-publish-helper-qos0-v5.py index a011f9d9..1b59113d 100644 --- a/tests/lib/clients/03-publish-helper-qos0-v5.py +++ b/tests/lib/clients/03-publish-helper-qos0-v5.py @@ -1,7 +1,7 @@ import paho.mqtt.client import paho.mqtt.publish -from tests.paho_test import wait_for_keyboard_interrupt +from tests.paho_test import get_test_server_port, wait_for_keyboard_interrupt with wait_for_keyboard_interrupt(): paho.mqtt.publish.single( @@ -9,7 +9,7 @@ "message", qos=0, hostname="localhost", - port=1888, + port=get_test_server_port(), client_id="publish-helper-qos0-test", protocol=paho.mqtt.client.MQTTv5, ) diff --git a/tests/lib/clients/03-publish-helper-qos0.py b/tests/lib/clients/03-publish-helper-qos0.py index 70145196..a7b696eb 100644 --- a/tests/lib/clients/03-publish-helper-qos0.py +++ b/tests/lib/clients/03-publish-helper-qos0.py @@ -1,6 +1,6 @@ import paho.mqtt.publish -from tests.paho_test import wait_for_keyboard_interrupt +from tests.paho_test import get_test_server_port, wait_for_keyboard_interrupt with wait_for_keyboard_interrupt(): paho.mqtt.publish.single( @@ -8,6 +8,6 @@ "message", qos=0, hostname="localhost", - port=1888, + port=get_test_server_port(), client_id="publish-helper-qos0-test", ) diff --git a/tests/lib/clients/03-publish-helper-qos1-disconnect.py b/tests/lib/clients/03-publish-helper-qos1-disconnect.py index 88c99274..b07166f6 100644 --- a/tests/lib/clients/03-publish-helper-qos1-disconnect.py +++ b/tests/lib/clients/03-publish-helper-qos1-disconnect.py @@ -1,6 +1,6 @@ import paho.mqtt.publish -from tests.paho_test import wait_for_keyboard_interrupt +from tests.paho_test import get_test_server_port, wait_for_keyboard_interrupt with wait_for_keyboard_interrupt(): paho.mqtt.publish.single( @@ -8,6 +8,6 @@ "message", qos=1, hostname="localhost", - port=1888, + port=get_test_server_port(), client_id="publish-helper-qos1-disconnect-test", ) diff --git a/tests/lib/clients/03-publish-qos0-no-payload.py b/tests/lib/clients/03-publish-qos0-no-payload.py index e6bea409..37458a83 100644 --- a/tests/lib/clients/03-publish-qos0-no-payload.py +++ b/tests/lib/clients/03-publish-qos0-no-payload.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt sent_mid = -1 @@ -20,5 +20,5 @@ def on_publish(mqttc, obj, mid): mqttc.on_connect = on_connect mqttc.on_publish = on_publish -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/03-publish-qos0.py b/tests/lib/clients/03-publish-qos0.py index 60c3f6c5..85386dda 100644 --- a/tests/lib/clients/03-publish-qos0.py +++ b/tests/lib/clients/03-publish-qos0.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt sent_mid = -1 @@ -22,5 +22,5 @@ def on_publish(mqttc, obj, mid): mqttc.on_connect = on_connect mqttc.on_publish = on_publish -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/04-retain-qos0.py b/tests/lib/clients/04-retain-qos0.py index 410ee82f..b50a7381 100644 --- a/tests/lib/clients/04-retain-qos0.py +++ b/tests/lib/clients/04-retain-qos0.py @@ -1,6 +1,6 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -11,5 +11,5 @@ def on_connect(mqttc, obj, flags, rc): mqttc = mqtt.Client("retain-qos0-test", clean_session=True) mqttc.on_connect = on_connect -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/08-ssl-connect-cert-auth-pw.py b/tests/lib/clients/08-ssl-connect-cert-auth-pw.py index edcc00d0..7f97df5f 100644 --- a/tests/lib/clients/08-ssl-connect-cert-auth-pw.py +++ b/tests/lib/clients/08-ssl-connect-cert-auth-pw.py @@ -2,7 +2,7 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -24,5 +24,5 @@ def on_disconnect(mqttc, obj, rc): mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/08-ssl-connect-cert-auth.py b/tests/lib/clients/08-ssl-connect-cert-auth.py index 78a5bbc0..f907e38c 100644 --- a/tests/lib/clients/08-ssl-connect-cert-auth.py +++ b/tests/lib/clients/08-ssl-connect-cert-auth.py @@ -2,7 +2,7 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -23,5 +23,5 @@ def on_disconnect(mqttc, obj, rc): mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/08-ssl-connect-no-auth.py b/tests/lib/clients/08-ssl-connect-no-auth.py index cd0d1411..43c3d01f 100644 --- a/tests/lib/clients/08-ssl-connect-no-auth.py +++ b/tests/lib/clients/08-ssl-connect-no-auth.py @@ -2,7 +2,7 @@ import paho.mqtt.client as mqtt -from tests.paho_test import loop_until_keyboard_interrupt +from tests.paho_test import get_test_server_port, loop_until_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -19,5 +19,5 @@ def on_disconnect(mqttc, obj, rc): mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect -mqttc.connect("localhost", 1888) +mqttc.connect("localhost", get_test_server_port()) loop_until_keyboard_interrupt(mqttc) diff --git a/tests/lib/clients/08-ssl-fake-cacert.py b/tests/lib/clients/08-ssl-fake-cacert.py index e309e1bc..04b146ed 100644 --- a/tests/lib/clients/08-ssl-fake-cacert.py +++ b/tests/lib/clients/08-ssl-fake-cacert.py @@ -3,7 +3,7 @@ import paho.mqtt.client as mqtt -from tests.paho_test import wait_for_keyboard_interrupt +from tests.paho_test import get_test_server_port, wait_for_keyboard_interrupt def on_connect(mqttc, obj, flags, rc): @@ -20,7 +20,7 @@ def on_connect(mqttc, obj, flags, rc): with wait_for_keyboard_interrupt(): try: - mqttc.connect("localhost", 1888) + mqttc.connect("localhost", get_test_server_port()) except ssl.SSLError as msg: assert msg.errno == 1 and "certificate verify failed" in msg.strerror else: diff --git a/tests/lib/conftest.py b/tests/lib/conftest.py index 3e2853e8..b2be3cbf 100644 --- a/tests/lib/conftest.py +++ b/tests/lib/conftest.py @@ -12,8 +12,9 @@ @pytest.fixture() -def server_socket(): - sock = create_server_socket() +def server_socket(monkeypatch): + sock, port = create_server_socket() + monkeypatch.setenv("PAHO_SERVER_PORT", str(port)) try: yield sock finally: @@ -21,8 +22,9 @@ def server_socket(): @pytest.fixture() -def ssl_server_socket(): - sock = create_server_socket_ssl() +def ssl_server_socket(monkeypatch): + sock, port = create_server_socket_ssl() + monkeypatch.setenv("PAHO_SERVER_PORT", str(port)) try: yield sock finally: @@ -51,6 +53,7 @@ def starter(name: str, expected_returncode: int = 0) -> None: PAHO_SSL_PATH=str(ssl_path), PYTHONPATH=f"{tests_path}{os.pathsep}{os.environ.get('PYTHONPATH', '')}", ) + assert 'PAHO_SERVER_PORT' in env, "PAHO_SERVER_PORT must be set in the environment when starting a client" # TODO: it would be nice to run this under `coverage` too! proc = subprocess.Popen([ sys.executable, diff --git a/tests/lib/test_01_keepalive_pingreq.py b/tests/lib/test_01_keepalive_pingreq.py index 0560f132..4c327db3 100644 --- a/tests/lib/test_01_keepalive_pingreq.py +++ b/tests/lib/test_01_keepalive_pingreq.py @@ -1,6 +1,6 @@ # Test whether a client sends a pingreq after the keepalive time -# The client should connect to port 1888 with keepalive=4, clean session set, +# The client should connect with keepalive=4, clean session set, # and client id 01-keepalive-pingreq # The client should send a PINGREQ message after the appropriate amount of time # (4 seconds after no traffic). diff --git a/tests/lib/test_01_no_clean_session.py b/tests/lib/test_01_no_clean_session.py index 531fa12e..7f00e544 100644 --- a/tests/lib/test_01_no_clean_session.py +++ b/tests/lib/test_01_no_clean_session.py @@ -1,6 +1,6 @@ # Test whether a client produces a correct connect with clean session not set. -# The client should connect to port 1888 with keepalive=60, clean session not +# The client should connect with keepalive=60, clean session not # set, and client id 01-no-clean-session. diff --git a/tests/lib/test_01_unpwd_empty_password_set.py b/tests/lib/test_01_unpwd_empty_password_set.py index 181ea00b..225d72bc 100644 --- a/tests/lib/test_01_unpwd_empty_password_set.py +++ b/tests/lib/test_01_unpwd_empty_password_set.py @@ -1,6 +1,6 @@ # Test whether a client produces a correct connect with a username and password. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # client id 01-unpwd-set, username set to uname and password set to empty string diff --git a/tests/lib/test_01_unpwd_empty_set.py b/tests/lib/test_01_unpwd_empty_set.py index 2bed58f4..8c51c22a 100644 --- a/tests/lib/test_01_unpwd_empty_set.py +++ b/tests/lib/test_01_unpwd_empty_set.py @@ -1,6 +1,6 @@ # Test whether a client produces a correct connect with a username and password. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # client id 01-unpwd-set, username and password set to empty string. diff --git a/tests/lib/test_01_unpwd_set.py b/tests/lib/test_01_unpwd_set.py index 6f67f947..38834ab9 100644 --- a/tests/lib/test_01_unpwd_set.py +++ b/tests/lib/test_01_unpwd_set.py @@ -1,6 +1,6 @@ # Test whether a client produces a correct connect with a username and password. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # client id 01-unpwd-set, username set to uname and password set to ;'[08gn=# diff --git a/tests/lib/test_01_unpwd_unicode_set.py b/tests/lib/test_01_unpwd_unicode_set.py index ed9c0074..875e00bf 100644 --- a/tests/lib/test_01_unpwd_unicode_set.py +++ b/tests/lib/test_01_unpwd_unicode_set.py @@ -1,6 +1,6 @@ # Test whether a client produces a correct connect with a unicode username and password. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # client id 01-unpwd-unicode-set, username and password from corresponding variables from __future__ import unicode_literals diff --git a/tests/lib/test_01_will_set.py b/tests/lib/test_01_will_set.py index 7da70862..55b55a25 100644 --- a/tests/lib/test_01_will_set.py +++ b/tests/lib/test_01_will_set.py @@ -1,7 +1,7 @@ # Test whether a client produces a correct connect with a will. # Will QoS=1, will retain=1. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # client id 01-will-set will topic set to topic/on/unexpected/disconnect , will # payload set to "will message", will qos set to 1 and will retain set. diff --git a/tests/lib/test_01_will_unpwd_set.py b/tests/lib/test_01_will_unpwd_set.py index 4c7ea36a..95c0517f 100644 --- a/tests/lib/test_01_will_unpwd_set.py +++ b/tests/lib/test_01_will_unpwd_set.py @@ -1,6 +1,6 @@ # Test whether a client produces a correct connect with a will, username and password. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # client id 01-will-unpwd-set , will topic set to "will-topic", will payload # set to "will message", will qos=2, will retain not set, username set to # "oibvvwqw" and password set to "#'^2hg9a&nm38*us". diff --git a/tests/lib/test_02_subscribe_qos0.py b/tests/lib/test_02_subscribe_qos0.py index 27f91b5c..d1ff422e 100644 --- a/tests/lib/test_02_subscribe_qos0.py +++ b/tests/lib/test_02_subscribe_qos0.py @@ -1,6 +1,6 @@ # Test whether a client sends a correct SUBSCRIBE to a topic with QoS 0. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id subscribe-qos0-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a SUBSCRIBE diff --git a/tests/lib/test_02_subscribe_qos1.py b/tests/lib/test_02_subscribe_qos1.py index 8d7c8eae..1e96d491 100644 --- a/tests/lib/test_02_subscribe_qos1.py +++ b/tests/lib/test_02_subscribe_qos1.py @@ -1,6 +1,6 @@ # Test whether a client sends a correct SUBSCRIBE to a topic with QoS 1. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id subscribe-qos1-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a SUBSCRIBE diff --git a/tests/lib/test_02_subscribe_qos2.py b/tests/lib/test_02_subscribe_qos2.py index cb9308b2..5d04aff5 100644 --- a/tests/lib/test_02_subscribe_qos2.py +++ b/tests/lib/test_02_subscribe_qos2.py @@ -1,6 +1,6 @@ # Test whether a client sends a correct SUBSCRIBE to a topic with QoS 2. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id subscribe-qos2-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a SUBSCRIBE diff --git a/tests/lib/test_03_publish_b2c_qos1.py b/tests/lib/test_03_publish_b2c_qos1.py index 15e22eae..20cc1f6d 100644 --- a/tests/lib/test_03_publish_b2c_qos1.py +++ b/tests/lib/test_03_publish_b2c_qos1.py @@ -1,6 +1,6 @@ # Test whether a client responds correctly to a PUBLISH with QoS 1. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id publish-qos1-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK the client should verify that rc==0. diff --git a/tests/lib/test_03_publish_helper_qos0.py b/tests/lib/test_03_publish_helper_qos0.py index 17a91764..1a2fac21 100644 --- a/tests/lib/test_03_publish_helper_qos0.py +++ b/tests/lib/test_03_publish_helper_qos0.py @@ -1,7 +1,7 @@ # Test whether a client sends a correct PUBLISH to a topic with QoS 0. # Use paho.mqtt.publish helper for that. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id publish-helper-qos0-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a PUBLISH message diff --git a/tests/lib/test_03_publish_helper_qos0_v5.py b/tests/lib/test_03_publish_helper_qos0_v5.py index d889d739..23722917 100644 --- a/tests/lib/test_03_publish_helper_qos0_v5.py +++ b/tests/lib/test_03_publish_helper_qos0_v5.py @@ -1,7 +1,7 @@ # Test whether a client sends a correct PUBLISH to a topic with QoS 0. # Use paho.mqtt.publish helper for that. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id publish-helper-qos0-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a PUBLISH message diff --git a/tests/lib/test_03_publish_qos0.py b/tests/lib/test_03_publish_qos0.py index 0bdcc1b0..018f39b9 100644 --- a/tests/lib/test_03_publish_qos0.py +++ b/tests/lib/test_03_publish_qos0.py @@ -1,6 +1,6 @@ # Test whether a client sends a correct PUBLISH to a topic with QoS 0. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id publish-qos0-test # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a PUBLISH message diff --git a/tests/lib/test_03_publish_qos0_no_payload.py b/tests/lib/test_03_publish_qos0_no_payload.py index 33b2c206..8cc39dbd 100644 --- a/tests/lib/test_03_publish_qos0_no_payload.py +++ b/tests/lib/test_03_publish_qos0_no_payload.py @@ -1,6 +1,6 @@ # Test whether a client sends a correct PUBLISH to a topic with QoS 0 and no payload. -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id publish-qos0-test-np # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a PUBLISH message diff --git a/tests/lib/test_08_ssl_connect_cert_auth.py b/tests/lib/test_08_ssl_connect_cert_auth.py index 3c467746..24e00d99 100644 --- a/tests/lib/test_08_ssl_connect_cert_auth.py +++ b/tests/lib/test_08_ssl_connect_cert_auth.py @@ -5,7 +5,7 @@ import tests.paho_test as paho_test from tests.paho_test import ssl -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id 08-ssl-connect-crt-auth # It should use the CA certificate ssl/all-ca.crt for verifying the server. # The test will send a CONNACK message to the client with rc=0. Upon receiving diff --git a/tests/lib/test_08_ssl_connect_cert_auth_pw.py b/tests/lib/test_08_ssl_connect_cert_auth_pw.py index 315b30c6..435bd6a7 100644 --- a/tests/lib/test_08_ssl_connect_cert_auth_pw.py +++ b/tests/lib/test_08_ssl_connect_cert_auth_pw.py @@ -5,7 +5,7 @@ import tests.paho_test as paho_test from tests.paho_test import ssl -# The client should connect to port 1888 with keepalive=60, clean session set, +# The client should connect with keepalive=60, clean session set, # and client id 08-ssl-connect-crt-auth # It should use the CA certificate ssl/all-ca.crt for verifying the server. # The test will send a CONNACK message to the client with rc=0. Upon receiving diff --git a/tests/lib/test_08_ssl_connect_no_auth.py b/tests/lib/test_08_ssl_connect_no_auth.py index dc42e266..efe64e10 100644 --- a/tests/lib/test_08_ssl_connect_no_auth.py +++ b/tests/lib/test_08_ssl_connect_no_auth.py @@ -1,6 +1,6 @@ # Test whether a client produces a correct connect and subsequent disconnect when using SSL. # -# The client should connect to port 1888 with keepalive=60, clean session set,# and client id 08-ssl-connect-no-auth +# The client should connect with keepalive=60, clean session set,# and client id 08-ssl-connect-no-auth # It should use the CA certificate ssl/all-ca.crt for verifying the server. # The test will send a CONNACK message to the client with rc=0. Upon receiving # the CONNACK and verifying that rc=0, the client should send a DISCONNECT diff --git a/tests/paho_test.py b/tests/paho_test.py index d9bf3b7c..a0f9a886 100644 --- a/tests/paho_test.py +++ b/tests/paho_test.py @@ -3,7 +3,6 @@ import os import socket import struct -import sys import time from tests.consts import ssl_path @@ -26,13 +25,25 @@ def __init__(self, message="Mismatched packets"): self.message = message +def bind_to_any_free_port(sock) -> int: + """ + Bind a socket to an available port on localhost, + and return the port number. + """ + while True: + try: + sock.bind(('', 0)) + return sock.getsockname()[1] + except OSError: + pass + + def create_server_socket(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.settimeout(10) - sock.bind(('', 1888)) + port = bind_to_any_free_port(sock) sock.listen(5) - return sock + return (sock, port) def create_server_socket_ssl(cert_reqs=None): @@ -57,9 +68,9 @@ def create_server_socket_ssl(cert_reqs=None): context.verify_mode = cert_reqs ssock = context.wrap_socket(sock, server_side=True) ssock.settimeout(10) - ssock.bind(('', 1888)) + port = bind_to_any_free_port(ssock) ssock.listen(5) - return ssock + return (ssock, port) def expect_packet(sock, name, expected): @@ -701,29 +712,6 @@ def pack_remaining_length(remaining_length): return s -def get_port(count=1): - if count == 1: - if len(sys.argv) == 2: - return int(sys.argv[1]) - else: - return 1888 - else: - if len(sys.argv) == 1+count: - p = () - for i in range(0, count): - p = p + (int(sys.argv[1+i]),) - return p - else: - return tuple(range(1888, 1888+count)) - - -def get_lib_port(): - if len(sys.argv) == 3: - return int(sys.argv[2]) - else: - return 1888 - - def do_ping(sock, error_string="pingresp"): do_send_receive(sock, gen_pingreq(), gen_pingresp(), error_string) @@ -773,3 +761,10 @@ def wait_for_keyboard_interrupt(): time.sleep(0.1) except KeyboardInterrupt: pass + + +def get_test_server_port() -> int: + """ + Get the port number for the test server. + """ + return int(os.environ['PAHO_SERVER_PORT']) diff --git a/tests/test_client.py b/tests/test_client.py index 59fdda60..2f1b45b5 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -29,7 +29,7 @@ def on_connect(mqttc, obj, flags, rc): mqttc.on_connect = on_connect - mqttc.connect_async("localhost", 1888) + mqttc.connect_async("localhost", fake_broker.port) mqttc.loop_start() try: @@ -67,7 +67,7 @@ def on_connect(mqttc, obj, flags, rc): mqttc.on_connect = on_connect - mqttc.connect_async("localhost", 1888) + mqttc.connect_async("localhost", fake_broker.port) mqttc.loop_start() try: @@ -104,7 +104,7 @@ def on_message(client, userdata, msg): mqttc.on_message = on_message - mqttc.connect_async("localhost", 1888) + mqttc.connect_async("localhost", fake_broker.port) mqttc.loop_start() try: @@ -148,7 +148,7 @@ def on_message(client, userdata, msg): mqttc.on_message = on_message - mqttc.connect_async("localhost", 1888) + mqttc.connect_async("localhost", fake_broker.port) mqttc.loop_start() try: @@ -188,7 +188,7 @@ def test_valid_utf8_topic_publish(self, fake_broker): # It should be non-ascii multi-bytes character topic = unicodedata.lookup('SNOWMAN') - mqttc.connect_async("localhost", 1888) + mqttc.connect_async("localhost", fake_broker.port) mqttc.loop_start() try: @@ -253,7 +253,7 @@ def callback2(client, userdata, msg): mqttc.message_callback_add('topic/callback/1', callback1) mqttc.message_callback_add('topic/callback/+', callback2) - mqttc.connect_async("localhost", 1888) + mqttc.connect_async("localhost", fake_broker.port) mqttc.loop_start() try: diff --git a/tests/test_websocket_integration.py b/tests/test_websocket_integration.py index b8a28309..6a54c0b2 100644 --- a/tests/test_websocket_integration.py +++ b/tests/test_websocket_integration.py @@ -60,7 +60,7 @@ def handle(_self): with fake_websocket_broker.serve(WebsocketHandler): with pytest.raises(WebsocketConnectionError) as exc: - mqttc.connect("localhost", 1888, keepalive=10) + mqttc.connect("localhost", fake_websocket_broker.port, keepalive=10) assert str(exc.value) == "WebSocket handshake error" @@ -103,7 +103,7 @@ def test_no_upgrade(self, proto_ver, proto_name, fake_websocket_broker, with fake_websocket_broker.serve(response): with pytest.raises(WebsocketConnectionError) as exc: - mqttc.connect("localhost", 1888, keepalive=10) + mqttc.connect("localhost", fake_websocket_broker.port, keepalive=10) assert str(exc.value) == "WebSocket handshake error, connection not upgraded" @@ -121,7 +121,7 @@ def test_bad_secret_key(self, proto_ver, proto_name, fake_websocket_broker, with fake_websocket_broker.serve(response): with pytest.raises(WebsocketConnectionError) as exc: - mqttc.connect("localhost", 1888, keepalive=10) + mqttc.connect("localhost", fake_websocket_broker.port, keepalive=10) assert str(exc.value) == "WebSocket handshake error, invalid secret key" @@ -179,7 +179,7 @@ def test_successful_connection(self, proto_ver, proto_name, response = self._get_callback_handler(init_response_headers) with fake_websocket_broker.serve(response): - mqttc.connect("localhost", 1888, keepalive=10) + mqttc.connect("localhost", fake_websocket_broker.port, keepalive=10) mqttc.disconnect() @@ -213,7 +213,7 @@ def check_path_correct(decoded): ) with fake_websocket_broker.serve(response): - mqttc.connect("localhost", 1888, keepalive=10) + mqttc.connect("localhost", fake_websocket_broker.port, keepalive=10) mqttc.disconnect() @@ -249,6 +249,6 @@ def check_headers_used(decoded): ) with fake_websocket_broker.serve(response): - mqttc.connect("localhost", 1888, keepalive=10) + mqttc.connect("localhost", fake_websocket_broker.port, keepalive=10) mqttc.disconnect() diff --git a/tests/testsupport/broker.py b/tests/testsupport/broker.py index b901a6df..85a283a8 100644 --- a/tests/testsupport/broker.py +++ b/tests/testsupport/broker.py @@ -13,7 +13,8 @@ def __init__(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.settimeout(30) - sock.bind(("localhost", 1888)) + sock.bind(("localhost", 0)) + self.port = sock.getsockname()[1] sock.listen(1) self._sock = sock @@ -71,7 +72,7 @@ def __init__(self): super(FakeWebsocketBroker, self).__init__() self.host = "localhost" - self.port = 1888 + self.port = -1 # Will be set by `serve()` self._server = None self._running = True @@ -79,10 +80,11 @@ def __init__(self): @contextlib.contextmanager def serve(self, tcphandler): - self._server = ThreadedTCPServer((self.host, self.port), tcphandler) + self._server = ThreadedTCPServer((self.host, 0), tcphandler) try: self.start() + self.port = self._server.server_address[1] if not self._running: raise RuntimeError("Error starting server") @@ -99,8 +101,6 @@ def run(self): @pytest.fixture def fake_websocket_broker(): - socketserver.TCPServer.allow_reuse_address = True - broker = FakeWebsocketBroker() yield broker