Skip to content

Commit

Permalink
Really skip this test on Windows :) (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia authored Apr 20, 2024
1 parent 29d5a7c commit d2acc20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import pytest
import pytest_asyncio

from .....tools import PlatformMarkers
from .base import BaseTestAsyncServer


Expand Down Expand Up @@ -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(
Expand Down
22 changes: 17 additions & 5 deletions tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d2acc20

Please sign in to comment.