From e3d923229c063992518f333cccd9791fce99d333 Mon Sep 17 00:00:00 2001 From: xqSimone Date: Wed, 18 Oct 2023 15:21:08 +0200 Subject: [PATCH] fix async tutorial006 and its tests --- docs_src/asynchronous/tutorial006.py | 2 +- .../test_asynchronous/test_tutorial006.py | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs_src/asynchronous/tutorial006.py b/docs_src/asynchronous/tutorial006.py index e3c9abbf63..6901707269 100644 --- a/docs_src/asynchronous/tutorial006.py +++ b/docs_src/asynchronous/tutorial006.py @@ -12,7 +12,7 @@ async def wait_trio(seconds: int): typer.echo(f"Waited for {seconds} seconds using trio (default)") -@app.callback(invoke_without_command=True, async_runner=lambda c: asyncio.run(c)) +@app.callback(async_runner=lambda c: asyncio.run(c)) async def wait_asyncio(seconds: int): await asyncio.sleep(seconds) typer.echo( diff --git a/tests/test_tutorial/test_asynchronous/test_tutorial006.py b/tests/test_tutorial/test_asynchronous/test_tutorial006.py index c5863d427d..36c8ffbd47 100644 --- a/tests/test_tutorial/test_asynchronous/test_tutorial006.py +++ b/tests/test_tutorial/test_asynchronous/test_tutorial006.py @@ -1,6 +1,7 @@ import subprocess import sys +import pytest from typer.testing import CliRunner from docs_src.asynchronous import tutorial006 as mod @@ -10,22 +11,19 @@ runner = CliRunner() -def test_wait_trio(): - result = runner.invoke(app, ["2"]) +def test_wait_asyncio(): + result = runner.invoke(app, ["1", "wait-trio", "2"]) assert result.exit_code == 0 assert ( - "Waited for 2 seconds before running command using asyncio (customized)" - in result.output + "Waited for 1 seconds before running command using asyncio (customized)\n" + "Waited for 2 seconds using trio (default)" in result.output ) -def test_wait_asyncio(): - result = runner.invoke(app, ["2"]) - assert result.exit_code == 0 - assert ( - "Waited for 2 seconds before running command using asyncio (customized)" - in result.output - ) +@pytest.mark.anyio +@pytest.mark.parametrize("anyio_backend", ["asyncio"]) +async def test_callback(anyio_backend): + await mod.wait_asyncio(2) def test_script():