44import enum
55import functools
66import inspect
7+ import os
78import socket
89import sys
910import warnings
@@ -659,9 +660,7 @@ def _patched_collect():
659660 # to all items in the package.
660661 # see also https://github.com/pytest-dev/pytest/issues/11662#issuecomment-1879310072 # noqa
661662 # Possibly related to https://github.com/pytest-dev/pytest/issues/4085
662- fixture_id = (
663- str (Path (pkg_nodeid ).joinpath ("__init__.py" )) + "::<event_loop>"
664- )
663+ fixture_id = f"{ pkg_nodeid } /__init__.py::<event_loop>" .lstrip ("/" )
665664 # When collector is a Package, collector.obj is the package's
666665 # __init__.py. Accessing the __init__.py to attach the fixture function
667666 # may trigger additional module imports or change the order of imports,
@@ -677,13 +676,18 @@ def _patched_collect():
677676 dir = pkgdir ,
678677 prefix = "pytest_asyncio_virtual_module_" ,
679678 suffix = ".py" ,
679+ delete = False , # Required for Windows compatibility
680680 ) as virtual_module_file :
681681 virtual_module = Module .from_parent (
682682 collector , path = Path (virtual_module_file .name )
683683 )
684684 virtual_module_file .write (
685685 dedent (
686686 f"""\
687+ # This is a temporary file created by pytest-asyncio
688+ # If you see this file, a pytest run has crashed and
689+ # wasn't able to clean up the file in time.
690+ # You can safely remove this file.
687691 import asyncio
688692 import pytest
689693 from pytest_asyncio.plugin \
@@ -715,6 +719,7 @@ def scoped_event_loop(
715719 # see also https://github.com/pytest-dev/pytest/issues/11662#issuecomment-1879310072 # noqa
716720 fixturemanager .parsefactories (virtual_module .obj , nodeid = pkg_nodeid )
717721 yield virtual_module
722+ os .unlink (virtual_module_file .name )
718723 yield from collector .__original_collect ()
719724
720725 collector .__original_collect = collector .collect
0 commit comments