From 2f88a8ef5608f01291cb30431c447d0e156f83c4 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Wed, 10 Jan 2024 18:38:53 +0100 Subject: [PATCH 1/4] [build] Run tests on Windows. The use of temporary files for injecting fixtures into packages shows platform-specific behavior. As a result, it makes sense to run the tests on Windows as well, at least as long as the virtual module workaround is in place. Signed-off-by: Michael Seifert --- .github/workflows/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6aeaaa83..972620a1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,11 +56,12 @@ jobs: path: dist test: - name: Python ${{ matrix.python-version }} - runs-on: ubuntu-latest + name: ${{ matrix.os }} - Python ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} strategy: matrix: + os: [ubuntu-latest, windows-latest] python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: @@ -75,7 +76,6 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - set -xe python -VV python -m site python -m pip install --upgrade pip @@ -85,6 +85,7 @@ jobs: - name: Store coverage data uses: actions/upload-artifact@v3 + if: "!endsWith(matrix.os, 'windows')" with: name: coverage-per-interpreter path: .coverage.* From ac2875f7e664046c7fa387d04506d52790261768 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Wed, 10 Jan 2024 19:12:05 +0100 Subject: [PATCH 2/4] [tests] Fixed deprecated use of yield_fixture in test. Signed-off-by: Michael Seifert --- tests/test_subprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index 14d3498a..f60b2824 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -8,7 +8,7 @@ # The default asyncio event loop implementation on Windows does not # support subprocesses. Subprocesses are available for Windows if a # ProactorEventLoop is used. - @pytest.yield_fixture() + @pytest.fixture() def event_loop(): loop = asyncio.ProactorEventLoop() yield loop From 00ee075468077220aef6dfee215cca9174e830c7 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Wed, 10 Jan 2024 19:13:29 +0100 Subject: [PATCH 3/4] [ci] Shorten names of display OS in CI jobs. Signed-off-by: Michael Seifert --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 972620a1..6f240e0a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,11 +57,11 @@ jobs: test: name: ${{ matrix.os }} - Python ${{ matrix.python-version }} - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.os }}-latest strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu, windows] python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: From 705f745f1eba3ab9d76234b8b9de9df44d2906cf Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Wed, 10 Jan 2024 19:15:09 +0100 Subject: [PATCH 4/4] [fix] Make virtual modules compatible with Windows. Signed-off-by: Michael Seifert --- pytest_asyncio/plugin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index cfc28e8d..a1bdbd91 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -4,6 +4,7 @@ import enum import functools import inspect +import os import socket import sys import warnings @@ -659,9 +660,7 @@ def _patched_collect(): # to all items in the package. # see also https://github.com/pytest-dev/pytest/issues/11662#issuecomment-1879310072 # noqa # Possibly related to https://github.com/pytest-dev/pytest/issues/4085 - fixture_id = ( - str(Path(pkg_nodeid).joinpath("__init__.py")) + "::" - ) + fixture_id = f"{pkg_nodeid}/__init__.py::".lstrip("/") # When collector is a Package, collector.obj is the package's # __init__.py. Accessing the __init__.py to attach the fixture function # may trigger additional module imports or change the order of imports, @@ -677,6 +676,7 @@ def _patched_collect(): dir=pkgdir, prefix="pytest_asyncio_virtual_module_", suffix=".py", + delete=False, # Required for Windows compatibility ) as virtual_module_file: virtual_module = Module.from_parent( collector, path=Path(virtual_module_file.name) @@ -684,6 +684,10 @@ def _patched_collect(): virtual_module_file.write( dedent( f"""\ + # This is a temporary file created by pytest-asyncio + # If you see this file, a pytest run has crashed and + # wasn't able to clean up the file in time. + # You can safely remove this file. import asyncio import pytest from pytest_asyncio.plugin \ @@ -715,6 +719,7 @@ def scoped_event_loop( # see also https://github.com/pytest-dev/pytest/issues/11662#issuecomment-1879310072 # noqa fixturemanager.parsefactories(virtual_module.obj, nodeid=pkg_nodeid) yield virtual_module + os.unlink(virtual_module_file.name) yield from collector.__original_collect() collector.__original_collect = collector.collect