agronholm / agronholm/anyio

Provide async `getfixturevalue()` method on anyio

Open
#720 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
2.5k
Forks
260
Avg merge
1d 8h
Merged PRs (30d)
17

Description

### Things to check first

- [X] I have searched the existing issues and didn't find my feature already requested there

### Feature description

Pytest allows to retrieve a fixture value by injecting the fixture as a function argument or by using `request.getfixturevalue()`. The latter fails to provide the value of an async fixture.

```py
import pytest

pytestmark = pytest.mark.anyio

@pytest.fixture
def anyio_backend():
return "asyncio"

@pytest.fixture
async def f():
return 1

async def test_problem(request):
assert request.getfixturevalue('f') == 1

async def test_ok(f):
assert f == 1
```

### Use case

According to the docs [1], `getfixturevalue()` runs a fixture dynamically. This feature is not available in anyio currently for async fixtures. However, I would like to make use of it to decide if I need to run a specific fixture based on the value of another fixture.

From the docs:

> Dynamically run a named fixture function.
>
> Declaring fixtures via function argument is recommended where possible. But if you can only decide whether to use another > fixture at test setup time, you may use this function to retrieve it inside a fixture or test function body.

[1] https://docs.pytest.org/en/7.1.x/reference/reference.html

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.