diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6aeaaa83..6f240e0a 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 }}-latest strategy: matrix: + os: [ubuntu, windows] 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.* 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 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