From 2ebcc7126834472d3922d9c512df5438ebbf1cb8 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Thu, 22 Jun 2023 19:07:03 +0200 Subject: [PATCH] No serialize of test. --- test/sub_transport/test_comm.py | 75 ++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/test/sub_transport/test_comm.py b/test/sub_transport/test_comm.py index 8d39c70b0e..bdc573f1fa 100644 --- a/test/sub_transport/test_comm.py +++ b/test/sub_transport/test_comm.py @@ -7,6 +7,7 @@ from pymodbus.transport.transport import CommType +BASE_PORT = 6100 COMM_TYPES = [ CommType.TCP, CommType.TLS, @@ -18,26 +19,34 @@ class TestCommTransport: """Test for the transport module.""" - @pytest.mark.xdist_group(name="server_serialize") - @pytest.mark.parametrize("use_comm_type", COMM_TYPES) - async def test_connect(self, client, use_comm_type, use_port): + @pytest.mark.parametrize( + ("use_comm_type", "use_port"), + [ + (CommType.TCP, BASE_PORT + 1), + (CommType.TLS, BASE_PORT + 2), + # (CommType.UDP, BASE_PORT + 3), udp is connectionless. + (CommType.SERIAL, BASE_PORT + 4), + ], + ) + async def test_connect(self, client): """Test connect().""" - if use_comm_type == CommType.UDP: - # always true, since udp is connectionless. - return start = time.time() assert not await client.transport_connect() delta = time.time() - start assert delta < client.comm_params.timeout_connect * 1.2 client.close() - @pytest.mark.xdist_group(name="server_serialize") - @pytest.mark.parametrize("use_comm_type", COMM_TYPES) - async def test_connect_not_ok(self, client, use_comm_type, use_port): + @pytest.mark.parametrize( + ("use_comm_type", "use_port"), + [ + (CommType.TCP, BASE_PORT + 5), + (CommType.TLS, BASE_PORT + 6), + # (CommType.UDP, BASE_PORT + 7), udp is connectionless. + (CommType.SERIAL, BASE_PORT + 8), + ], + ) + async def test_connect_not_ok(self, client): """Test connect().""" - if use_comm_type == CommType.UDP: - # always true, since udp is connectionless. - return client.comm_params.host = "/illegal_host" start = time.time() assert not await client.transport_connect() @@ -45,29 +54,47 @@ async def test_connect_not_ok(self, client, use_comm_type, use_port): assert delta < client.comm_params.timeout_connect * 1.2 client.close() - @pytest.mark.xdist_group(name="server_serialize") - @pytest.mark.parametrize("use_comm_type", COMM_TYPES) - async def test_listen(self, server, use_comm_type): + @pytest.mark.parametrize( + ("use_comm_type", "use_port"), + [ + (CommType.TCP, BASE_PORT + 9), + (CommType.TLS, BASE_PORT + 10), + (CommType.UDP, BASE_PORT + 11), + # (CommType.SERIAL, BASE_PORT + 12), there are no standard tty port + ], + ) + async def test_listen(self, server): """Test listen().""" - if use_comm_type == CommType.SERIAL: - # there are no positive test, since there are no standard tty port - return assert await server.transport_listen() assert server.transport server.close() - @pytest.mark.xdist_group(name="server_serialize") - @pytest.mark.parametrize("use_comm_type", COMM_TYPES) - async def test_listen_not_ok(self, server, use_comm_type): + @pytest.mark.parametrize( + ("use_comm_type", "use_port"), + [ + (CommType.TCP, BASE_PORT + 13), + (CommType.TLS, BASE_PORT + 14), + (CommType.UDP, BASE_PORT + 15), + (CommType.SERIAL, BASE_PORT + 16), + ], + ) + async def test_listen_not_ok(self, server): """Test listen().""" server.comm_params.host = "/illegal_host" assert not await server.transport_listen() assert not server.transport server.close() - @pytest.mark.xdist_group(name="server_serialize") - @pytest.mark.parametrize("use_comm_type", COMM_TYPES) - async def test_connected(self, client, server, use_comm_type, commparams): + @pytest.mark.parametrize( + ("use_comm_type", "use_port"), + [ + (CommType.TCP, BASE_PORT + 13), + (CommType.TLS, BASE_PORT + 14), + (CommType.UDP, BASE_PORT + 15), + (CommType.SERIAL, BASE_PORT + 16), + ], + ) + async def test_connected(self, client, server, use_comm_type): """Test connection and data exchange.""" assert await server.transport_listen() assert await client.transport_connect()