From d2acc20514bb582c075f3829ed086e0d0f39514d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francis=20Clairicia-Rose-Claire-Jos=C3=A9phine?= Date: Sat, 20 Apr 2024 20:53:59 +0200 Subject: [PATCH] Really skip this test on Windows :) (#275) --- .../test_async/test_server/test_tcp.py | 3 ++- tests/tools.py | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/functional_test/test_communication/test_async/test_server/test_tcp.py b/tests/functional_test/test_communication/test_async/test_server/test_tcp.py index 7798085a..9b40139f 100644 --- a/tests/functional_test/test_communication/test_async/test_server/test_tcp.py +++ b/tests/functional_test/test_communication/test_async/test_server/test_tcp.py @@ -28,6 +28,7 @@ import pytest import pytest_asyncio +from .....tools import PlatformMarkers from .base import BaseTestAsyncServer @@ -578,7 +579,7 @@ async def test____serve_forever____accept_client( assert client_address not in request_handler.connected_clients # skip Windows for this test, the ECONNRESET will happen on socket.send() or socket.recv() - @pytest.mark.xfail('sys.platform == "win32"', reason="socket.getpeername() works by some magic") + @PlatformMarkers.skipif_platform_win32_because("socket.getpeername() works by some magic on Windows") @pytest.mark.parametrize("socket_family", ["AF_INET"], indirect=True) @pytest.mark.parametrize("use_ssl", ["NO_SSL"], indirect=True) async def test____serve_forever____accept_client____client_sent_RST_packet_right_after_accept( diff --git a/tests/tools.py b/tests/tools.py index 7a09cf6d..d2c0ffe4 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -17,15 +17,27 @@ _V_co = TypeVar("_V_co", covariant=True) -def _make_skipif_platform(platform: str) -> pytest.MarkDecorator: - return pytest.mark.skipif(sys.platform.startswith(platform), reason=f"cannot run on platform {platform!r}") +def _make_skipif_platform(platform: str, reason: str) -> pytest.MarkDecorator: + return pytest.mark.skipif(sys.platform.startswith(platform), reason=reason) @final class PlatformMarkers: - skipif_platform_win32 = _make_skipif_platform("win32") - skipif_platform_macOS = _make_skipif_platform("darwin") - skipif_platform_linux = _make_skipif_platform("linux") + @staticmethod + def skipif_platform_win32_because(reason: str) -> pytest.MarkDecorator: + return _make_skipif_platform("win32", reason) + + @staticmethod + def skipif_platform_macOS_because(reason: str) -> pytest.MarkDecorator: + return _make_skipif_platform("darwin", reason) + + @staticmethod + def skipif_platform_linux_because(reason: str) -> pytest.MarkDecorator: + return _make_skipif_platform("linux", reason) + + skipif_platform_win32 = skipif_platform_win32_because("cannot run on Windows") + skipif_platform_macOS = skipif_platform_macOS_because("cannot run on MacOS") + skipif_platform_linux = skipif_platform_linux_because("cannot run on Linux") def send_return(gen: Generator[Any, _T_contra, _V_co], value: _T_contra, /) -> _V_co: