4
4
import enum
5
5
import functools
6
6
import inspect
7
+ import os
7
8
import socket
8
9
import sys
9
10
import warnings
@@ -659,9 +660,7 @@ def _patched_collect():
659
660
# to all items in the package.
660
661
# see also https://github.com/pytest-dev/pytest/issues/11662#issuecomment-1879310072 # noqa
661
662
# 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 ("/" )
665
664
# When collector is a Package, collector.obj is the package's
666
665
# __init__.py. Accessing the __init__.py to attach the fixture function
667
666
# may trigger additional module imports or change the order of imports,
@@ -677,13 +676,18 @@ def _patched_collect():
677
676
dir = pkgdir ,
678
677
prefix = "pytest_asyncio_virtual_module_" ,
679
678
suffix = ".py" ,
679
+ delete = False , # Required for Windows compatibility
680
680
) as virtual_module_file :
681
681
virtual_module = Module .from_parent (
682
682
collector , path = Path (virtual_module_file .name )
683
683
)
684
684
virtual_module_file .write (
685
685
dedent (
686
686
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.
687
691
import asyncio
688
692
import pytest
689
693
from pytest_asyncio.plugin \
@@ -715,6 +719,7 @@ def scoped_event_loop(
715
719
# see also https://github.com/pytest-dev/pytest/issues/11662#issuecomment-1879310072 # noqa
716
720
fixturemanager .parsefactories (virtual_module .obj , nodeid = pkg_nodeid )
717
721
yield virtual_module
722
+ os .unlink (virtual_module_file .name )
718
723
yield from collector .__original_collect ()
719
724
720
725
collector .__original_collect = collector .collect
0 commit comments