Deprecate @pytest_asyncio.fixture for synchronous fixtures#1473
Conversation
Widen _R TypeVar (removing the Awaitable|AsyncIterator bound) so that @pytest_asyncio.fixture can be applied to synchronous functions without a type error. Emit PytestDeprecationWarning at decoration time when the decorated function is not a coroutine or async generator function. The internal synchronizer wrapper in pytest_fixture_setup bypasses _make_asyncio_fixture_function to avoid a false-positive warning. Closes pytest-dev#1090
6a90da5 to
03c9ab8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1473 +/- ##
==========================================
+ Coverage 94.50% 94.54% +0.03%
==========================================
Files 2 2
Lines 510 513 +3
Branches 62 63 +1
==========================================
+ Hits 482 485 +3
Misses 22 22
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The PR relaxes type constraints on While the submitted patch technically solves the linked issue, the chosen approach defeats the purpose of typed code, which tries to catch issues in a static analysis step as opposed to at runtime. Users will also lose typing errors for the deprecated use in their IDEs and editors. Unless you can convince me otherwise, I'll close this PR. |
Using
@pytest_asyncio.fixtureon a synchronous function is a user mistake — synchronous fixtures should use@pytest.fixture. Previously this silently succeeded, making the error hard to diagnose.This PR:
_R = TypeVar("_R")(removes theAwaitable | AsyncIteratorbound) so applying@pytest_asyncio.fixtureto a sync function no longer raises a type error before the warning fires.PytestDeprecationWarningat decoration time when the decorated function is not a coroutine or async generator.Closes #1090