Skip to content

Commit

Permalink
fix async tutorial006 and its tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xqSimone committed Oct 18, 2023
1 parent 4be4aa4 commit e3d9232
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs_src/asynchronous/tutorial006.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 9 additions & 11 deletions tests/test_tutorial/test_asynchronous/test_tutorial006.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
from typer.testing import CliRunner

from docs_src.asynchronous import tutorial006 as mod
Expand All @@ -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():
Expand Down

0 comments on commit e3d9232

Please sign in to comment.