Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide async getfixturevalue() method on anyio #720

Open
1 task done
chbndrhnns opened this issue Apr 15, 2024 · 0 comments
Open
1 task done

Provide async getfixturevalue() method on anyio #720

chbndrhnns opened this issue Apr 15, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@chbndrhnns
Copy link

Things to check first

  • 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.

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

@chbndrhnns chbndrhnns added the enhancement New feature or request label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant