Dynamically calling async fixture causes a runtime error saying "This event loop is already running"
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 50/100
Direzione di ricerca
Inizia riproducendo i casi di fixture dinamici e fissi in tests/test_app_factory.py, quindi esamina pytest_asyncio/plugin.py intorno al wrapper alla riga 97 e il percorso di pytest.request.getfixturevalue mostrato nel traceback. Il lavoro è completato quando il test del fixture async dinamico termina senza l’errore di runtime dell’event loop e restituisce il valore del fixture previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
There seems to be a bug with how request.getfixturevalue(argname) interacts with pytest-asyncio. Calling the function leads to a runtime error saying the event loop is already running. If you change it from being dynamically called to being fixed in the function definition, it works as expected.
Platform Info:
platform win32 -- Python 3.7.2, pytest-4.2.0, py-1.7.0, pluggy-0.8.1
plugins: asyncio-0.11.0.dev0
Test fixture that can be used in both dynamic/fixed cases:
@pytest.fixture
async def async_fixture():
yield 'Hi from async_fixture()!'
Successful fixed function argument fixture test:
@pytest.mark.asyncio
async def test_async_fixture_fixed(async_fixture):
assert async_fixture == 'Hi from async_fixture()!'
Failed dynamic fixture test:
@pytest.mark.asyncio
async def test_async_fixture_dynamic(request):
async_fixture = request.getfixturevalue('async_fixture')
assert async_fixture == 'Hi from async_fixture()!'
Failed test trace-back:
================================== FAILURES ===================================
_________________________ test_async_fixture_dynamic __________________________
request = <FixtureRequest for <Function test_async_fixture_dynamic>>
@pytest.mark.asyncio
async def test_async_fixture_dynamic(request):
> async_fixture = request.getfixturevalue('async_fixture')
tests\test_app_factory.py:52:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv\lib\site-packages\_pytest\fixtures.py:478: in getfixturevalue
return self._get_active_fixturedef(argname).cached_result[0]
venv\lib\site-packages\_pytest\fixtures.py:501: in _get_active_fixturedef
self._compute_fixture_value(fixturedef)
venv\lib\site-packages\_pytest\fixtures.py:586: in _compute_fixture_value
fixturedef.execute(request=subrequest)
venv\lib\site-packages\_pytest\fixtures.py:881: in execute
return hook.pytest_fixture_setup(fixturedef=self, request=request)
venv\lib\site-packages\pluggy\hooks.py:284: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
venv\lib\site-packages\pluggy\manager.py:68: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
venv\lib\site-packages\pluggy\manager.py:62: in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
venv\lib\site-packages\_pytest\fixtures.py:923: in pytest_fixture_setup
result = call_fixture_func(fixturefunc, request, kwargs)
venv\lib\site-packages\_pytest\fixtures.py:782: in call_fixture_func
res = fixturefunc(**kwargs)
..\pytest-asyncio\pytest_asyncio\plugin.py:97: in wrapper
return loop.run_until_complete(setup())
C:\Users\ykuzm\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py:571: in run_until_complete
self.run_forever()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_WindowsSelectorEventLoop running=False closed=False debug=False>
def run_forever(self):
"""Run until stop() is called."""
self._check_closed()
if self.is_running():
> raise RuntimeError('This event loop is already running')
E RuntimeError: This event loop is already running
- Lingua principale
- Python
- Stelle
- 1.7k
- Fork
- 209
- Merge medio
- 1h 51m
- PR unite (30g)
- 13
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pytest-dev/pytest-asyncio
-
Turn deprecation of the "scope" keyword argument of the asyncio marker into an errorForse già presa @mokashang l’ha presa 114 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
pytest-dev/pytest-asyncio#1475 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
pytest-dev/pytest-asyncio#1514 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Loop factory parametrization tears down async fixtures used by sync testsForse già presa @TLNing260310 l’ha presa 43 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
pytest-dev/pytest-asyncio#1501 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
`pytest_asyncio_loop_factories` hook is not called when `pytest.mark.asyncio` is added via parametrizationForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
pytest-dev/pytest-asyncio#1463 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Don't warn about `asyncio_default_fixture_loop_scope` unless the test suite uses `pytest-asyncio`Forse già presa @DawnofGenX l’ha presa 6 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
pytest-dev/pytest-asyncio#1344 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pytest-dev/pytest-asyncio
Issue simili
-
bug difficulty:2 good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
MakazhanAlpamys/Soup#1865 ·
I maintainer di solito rispondono entro 1 giorno
-
area: agents area: docs good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
openapi/gknowledge#23 ·
-
useless-suppression reported for deprecated-* messages that should be exemptForse già presa @adityasinha-ghub l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
pylint-dev/pylint#11656 ·
I maintainer di solito rispondono entro 1 giorno
-
area:provisioning effort:S priority:P2 provider:local-libvirt risk:daytime-only status:in-progress type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
randomparity/kdive#3203 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
get() for StrEnumForse già presa @FeJo5952 l’ha presa oggi. Apertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
collective/icalendar#1921 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno