fix: apply loop factories for asyncio marks via parametrize#1509
fix: apply loop factories for asyncio marks via parametrize#1509l46983284-cpu wants to merge 5 commits into
Conversation
When pytest.mark.asyncio is attached only to individual parameter sets, pytest_generate_tests still needs to resolve that marker so pytest_asyncio_loop_factories can parametrize the event loop. Fixes pytest-dev#1463 Signed-off-by: Alex Chen <l46983284@gmail.com>
Signed-off-by: Alex Chen <l46983284@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1509 +/- ##
==========================================
- Coverage 94.50% 92.39% -2.12%
==========================================
Files 2 2
Lines 510 539 +29
Branches 62 71 +9
==========================================
+ Hits 482 498 +16
- Misses 22 28 +6
- Partials 6 13 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| ], | ||
| ) | ||
| async def test_async(backend: str) -> None: | ||
| assert type(asyncio.get_running_loop()).__name__ == "CustomEventLoop" |
There was a problem hiding this comment.
I don't think this test covers the failure described in #1463. I would expect this PR to include a test that is parametrized via both pytest.mark.asyncio and pytest.mark.trio (or something analogous) with an assertion on loop type within the test body.
Address review on pytest-dev#1509: assert loop type for asyncio and an analogous non-asyncio backend mark in the same parametrize, matching the pytest-dev#1463 shape without adding pytest-trio to CI deps. Signed-off-by: Alex Chen <l46983284@gmail.com>
Move the pytest-dev#1509 review residual into its own test module so ruff format does not thrash the large existing pytester file. Covers asyncio + analogous non-asyncio backend marks with loop-type asserts (pytest-dev#1463 shape). Signed-off-by: Alex Chen <l46983284@gmail.com>
|
Thanks for the review — agreed the first regression was too narrow for the #1463 multi-backend shape. I added Focused tests green on this head. |
Match pre-commit shed/black parentheses collapse on pytester.dedent calls. Signed-off-by: Alex Chen <l46983284@gmail.com>
Summary
In strict mode,
pytest.mark.asynciocan be attached only to individual@pytest.mark.parametrizeparameter sets (for example multi-backend tests). Collection already turns those async parameter sets into Coroutine items, butpytest_generate_testsonly looked for a function-level asyncio marker. As a result,pytest_asyncio_loop_factorieswas never applied and the test kept the default event loop.This change resolves the asyncio marker from parametrize parameter sets when the function itself has no asyncio marker, so configured loop factories still parametrize
_asyncio_loop_factory.Tests
pytest.mark.asyncioand an analogous non-asyncio backend mark, asserting loop type in the test body (tests/test_loop_factory_parametrize_multi_backend.py). CI does not depend on pytest-trio; the second backend is a tiny inline plugin.python -m pytest tests/test_loop_factory_parametrization.py::test_asyncio_mark_via_parametrize_uses_hook_loop_factories tests/test_loop_factory_parametrize_multi_backend.py::test_asyncio_and_analogous_backend_parametrize_uses_loop_factories -qpython -m pyright pytest_asyncio/clean on this head.Fixes #1463