From 2f7c3e06a8827f8b4f8761c392c923c631b2467a Mon Sep 17 00:00:00 2001 From: Trim21 Date: Wed, 17 Apr 2024 20:36:11 +0800 Subject: [PATCH] fix test on win32 --- .github/workflows/test-suite.yml | 5 +++-- tests/client/test_async_client.py | 5 ++++- tests/test_multipart.py | 4 ++++ tests/test_timeouts.py | 4 ++++ tests/test_utils.py | 2 ++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 0bb570cedb..0195168f06 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -9,11 +9,12 @@ on: jobs: tests: - name: "Python ${{ matrix.python-version }}" - runs-on: "ubuntu-latest" + name: "Python ${{ matrix.python-version }} (${{ matrix.os }})" + runs-on: "${{ matrix.os }}-latest" strategy: matrix: + os: ["ubuntu", "windows"] python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index 8d7eaa3c58..893df6fcb8 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys import typing from datetime import timedelta @@ -18,7 +19,9 @@ async def test_get(server): assert response.http_version == "HTTP/1.1" assert response.headers assert repr(response) == "" - assert response.elapsed > timedelta(seconds=0) + if sys.platform != "win32": + # flaky on windows + assert response.elapsed > timedelta(seconds=0) @pytest.mark.parametrize( diff --git a/tests/test_multipart.py b/tests/test_multipart.py index 764f85a253..df067845cb 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -1,6 +1,7 @@ from __future__ import annotations import io +import sys import tempfile import typing @@ -371,6 +372,9 @@ def test_multipart_encode_files_raises_exception_with_StringIO_content() -> None httpx.Request("POST", url, data={}, files=files) # type: ignore +@pytest.mark.skipif( + sys.platform == "win32", reason="TemporaryFile on windows is binary mode" +) def test_multipart_encode_files_raises_exception_with_text_mode_file() -> None: url = "https://www.example.com" with tempfile.TemporaryFile(mode="w") as upload: diff --git a/tests/test_timeouts.py b/tests/test_timeouts.py index 666cc8e376..02e4fa7ac3 100644 --- a/tests/test_timeouts.py +++ b/tests/test_timeouts.py @@ -1,3 +1,5 @@ +import sys + import pytest import httpx @@ -12,6 +14,7 @@ async def test_read_timeout(server): await client.get(server.url.copy_with(path="/slow_response")) +@pytest.mark.skipif(sys.platform == "win32", reason="broken on windows") @pytest.mark.anyio async def test_write_timeout(server): timeout = httpx.Timeout(None, write=1e-6) @@ -33,6 +36,7 @@ async def test_connect_timeout(server): await client.get("http://10.255.255.1/") +@pytest.mark.skipif(sys.platform == "win32", reason="broken on windows") @pytest.mark.anyio async def test_pool_timeout(server): limits = httpx.Limits(max_connections=1) diff --git a/tests/test_utils.py b/tests/test_utils.py index f98a18f2cd..57584eaab7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,6 +2,7 @@ import logging import os import random +import sys import certifi import pytest @@ -122,6 +123,7 @@ def test_logging_redirect_chain(server, caplog): ] +@pytest.mark.skipif(sys.platform == "win32", reason="Path separator problem") def test_logging_ssl(caplog): caplog.set_level(logging.DEBUG) with httpx.Client():