Sync methods do not trigger async fixtures even if pytest.mark.anyio annotated
- 主要言語
- Python
- スター
- 2.5k
- フォーク
- 260
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 17
説明
### Things to check first
- [X] I have searched the existing issues and didn't find my bug already reported there
- [X] I have checked that my bug is still present in the latest release
### AnyIO version
4.6.0
### Python version
3.12
### What happened?
When trying to use this library with https://github.com/schireson/pytest-alembic (that has sync tests calling the async code https://pytest-alembic.readthedocs.io/en/latest/asyncio.html) I noticed that if you have an async fixture for a sync test, the fixture is not evaluated and instead the coroutine is inserted as value for the fixture.
### How can we reproduce the bug?
```python
from pytest_alembic import Config, MigrationContext
from pytest_alembic.tests import test_upgrade as upgrade
@pytest.fixture(scope="session") # must be session scoped to support sessions scooped DB setup
def anyio_backend() -> tuple[str, dict[str, bool]]:
return "asyncio", {"use_uvloop": True}
@pytest.fixture(scope="session", name="db")
async def _setup_db() -> None:
if await database_exists(ENGINE.url): # pragma: no branch
await drop_database(ENGINE.url) # pragma: no cover
await setup_db()
@pytest.mark.usefixtures("db")
async def test_upgrade(alembic_runner: MigrationContext) -> None: # noqa: RUF029 # fixture is async
upgrade(alembic_runner)
```
(Note I also ran into https://github.com/schireson/pytest-alembic/issues/119 when debugging this)
コントリビューションガイド
評価
この issue はまだ評価されていません。