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

request.getfixturevalue(name) does not work with async fixtures #976

Closed
Slarag opened this issue Oct 31, 2024 · 2 comments
Closed

request.getfixturevalue(name) does not work with async fixtures #976

Slarag opened this issue Oct 31, 2024 · 2 comments

Comments

@Slarag
Copy link

Slarag commented Oct 31, 2024

Current Behavior: Calling request.getfixturevalue(name) with the name of an async fixture raises a RuntimeError.
Expected Behavior: Calling request.getfixturevalue(name) with the name of an async fixture should initialize the fixture correctly.

Tested on Windows 11 23H2 with Python 3.11

Installed packages

colorama==0.4.6
iniconfig==2.0.0
packaging==24.1
pluggy==1.5.0
pytest==8.3.3
pytest-asyncio==0.24.0

conftest.py

@pytest.fixture(scope="function")
async def fixture1(request):
    return True

tests/test_getfixturevalue_async.py

import pytest

# This works
async def test_direct_fixture(fixture1):
    assert True

# This not
async def test_get_fixturevalue_async(request):
    x = request.getfixturevalue("fixture1")

Traceback

tests\test_getfixturevalue_async.py:7 (test_get_fixturevalue_async)
request = <FixtureRequest for <Coroutine test_get_fixturevalue_async>>

    async def test_get_fixturevalue_async(request):
>       x = request.getfixturevalue("fixture1")

test_getfixturevalue_async.py:9: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\.venv\Lib\site-packages\_pytest\fixtures.py:532: in getfixturevalue
    fixturedef = self._get_active_fixturedef(argname)
..\.venv\Lib\site-packages\_pytest\fixtures.py:617: in _get_active_fixturedef
    fixturedef.execute(request=subrequest)
..\.venv\Lib\site-packages\_pytest\fixtures.py:1091: in execute
    result = ihook.pytest_fixture_setup(fixturedef=self, request=request)
..\.venv\Lib\site-packages\pluggy\_hooks.py:513: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
..\.venv\Lib\site-packages\pluggy\_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
..\.venv\Lib\site-packages\_pytest\setuponly.py:36: in pytest_fixture_setup
    return (yield)
..\.venv\Lib\site-packages\_pytest\fixtures.py:1140: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
..\.venv\Lib\site-packages\_pytest\fixtures.py:898: in call_fixture_func
    fixture_result = fixturefunc(**kwargs)
..\.venv\Lib\site-packages\pytest_asyncio\plugin.py:366: in _async_fixture_wrapper
    return event_loop.run_until_complete(setup())
C:\Python\3.11\Lib\asyncio\base_events.py:630: in run_until_complete
    self._check_running()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <ProactorEventLoop running=False closed=False debug=False>

    def _check_running(self):
        if self.is_running():
>           raise RuntimeError('This event loop is already running')
E           RuntimeError: This event loop is already running

C:\Python\3.11\Lib\asyncio\base_events.py:589: RuntimeError
@Slarag
Copy link
Author

Slarag commented Oct 31, 2024

Duplicate of #112

@seifertm
Copy link
Contributor

seifertm commented Nov 6, 2024

Even if this is a duplicate, I appreciate your bug report, because it contains a concise reproducer. Thanks @Slarag !

@seifertm seifertm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2024
@seifertm seifertm added this to the v0.24 milestone Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants