Testing¶
app.invoke() runs your app in-process and returns stdout, stderr and the exit code separately:
from todo_axi.cli import app
run = app.invoke
def test_list_is_csv() -> None:
r = run("list --status open")
assert r.exit_code == 0
assert r.stdout.splitlines()[0] == "id,title,status,due"
assert r.stderr.startswith("count:")
def test_unknown_todo() -> None:
r = run("view 99")
assert r.exit_code == 1
assert r.stdout.startswith("error: todo 99 not found")
The first invoke() also checks your docstrings against the signatures. A docstring that
documents a parameter which no longer exists fails the test, and AXI(strict_docs=True) also
fails on parameters without help text.
To share the app between tests, return app.invoke from a fixture and annotate it with
Invoke:
import pytest
from fastaxi.axi import Invoke
@pytest.fixture
def run() -> Invoke:
from todo_axi.cli import app
return app.invoke