Would you find it useful if you could reliably fail tests that have unawaited coroutines?
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 20/100
Direzione di ricerca
Inizia con l'esempio di coroutine non attesa usando pytest.mark.asyncio e test_something_broken, quindi esamina le API proposte sys.set_unawaited_coroutine_tracking e sys.get_and_clear_unawaited_coroutines. L'issue non identifica file di implementazione né test, e il completamento dipende da una nuova API Python il cui design è ancora ipotetico.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Right now, this test passes:
async def do_something_broken():
assert False
@pytest.mark.asyncio
async def test_something_broken():
do_something_broken()
The reason is that we forgot the await in test_something_broken, so the broken code never actually ran. Oops. Python does issue a RuntimeWarning: coroutine 'do_something_broken' was never awaited, and recent pytest will print this at the end of tests, but this has a few issues:
- if your CI is green then how often do you click through to check for non-fatal warnings?
- since the warning isn't issued until the coroutine is garbage collected, on PyPy this can happen in some random other test, or if the test is near the end of the run it might never happen at all. E.g. with latest pypy3, pytest, and pytest-asyncio, the above test doesn't issue any warnings at all:
============================= test session starts ==============================
platform linux -- Python 3.5.3[pypy-5.8.0-beta], pytest-3.2.2, py-1.4.34, pluggy-0.4.0
rootdir: /tmp, inifile:
plugins: cov-2.5.1, catchlog-1.2.2, asyncio-0.7.0
collected 1 item
../../tmp/test.py .
=========================== 1 passed in 0.02 seconds ===========================
I'm considering proposing a new feature for Python 3.7, that would make it so pytest-asyncio could do:
# Ask Python to start maintaining a list of unawaited coroutines
sys.set_unawaited_coroutine_tracking(True)
try:
... run the test ...
finally:
# Get the unawaited coroutines
unawaited_coroutines = sys.get_and_clear_unawaited_coroutines()
sys.set_unawaited_coroutine_tracking(False)
if unawaited_coroutines:
# Issue an error that points to the actual problem
raise RuntimeError(f"Unawaited coroutines: {unawaited_coroutines}")
(Names etc. to be bikeshedded later; this is "API 2" in https://github.com/python-trio/trio/issues/79#issuecomment-325188030)
This way you could deterministically detect unawaited coroutines, reliably attribute them to the correct test, and cause it to fail with a useful error message.
Is this an API that you'd want to take advantage of if it were available?
- Lingua principale
- Python
- Stelle
- 1.7k
- Fork
- 207
- Merge medio
- 5h 2m
- PR unite (30g)
- 11
Preparare l'ambiente
Non abbiamo ancora controllato i file di configurazione di questo progetto. 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
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
pytest-dev/pytest-asyncio#1475 · 1 commento ·
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
-
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
-
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`Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
pytest-dev/pytest-asyncio#1344 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pytest-dev/pytest-asyncio
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
qgis/QGIS-Plugins-Website#459 ·
-
bug severity:medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
bot-found bug priority: P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
madenvel/KalinkaPlayer#179 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ls1intum/edutelligence#1098 ·
I maintainer di solito rispondono entro 1 giorno