Fixes a bug that breaks virtual modules on Windows #746
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
pytest-asyncio v0.23.4a0 introduced "virtual modules". These are temporary files in Python packages which contain a fixture definition. The files are removed after the virtual module was collected by pytest.
The use of temporary files has platform-specific behavior. Apparently, pytest opens the NamedTemporaryFile again, which causes issues on Windows. The the docs describe the problem and possible mitigations:
The
delete_on_close
flag has only been added in Python 3.12, so pytest-asyncio cannot use it at the moment. Neither does pytest-asyncio have the means to influence how pytest opens a file for collection. This leaves us with settingdelete=False
in the constructor of the NamedTemporaryFile and clean it up manually.This PR also enabled CI tests on Windows to reproduce the problem (and validate the fix).
See #729