-
First Check
Commit to Help
Example Codeimport typer
app = typer.Typer()
items_app = typer.Typer()
app.add_typer(items_app, name="items")
users_app = typer.Typer()
app.add_typer(users_app, name="users")
@items_app.command("create")
def items_create(item: str):
print(f"Creating item: {item}")
@items_app.command("delete")
def items_delete(item: str):
print(f"Deleting item: {item}")
@items_app.command("sell")
def items_sell(item: str):
print(f"Selling item: {item}")
@users_app.command("create")
def users_create(user_name: str):
print(f"Creating user: {user_name}")
@users_app.command("delete")
def users_delete(user_name: str):
print(f"Deleting user: {user_name}")
if __name__ == "__main__":
app() DescriptionFollowing something like https://typer.tiangolo.com/tutorial/subcommands/single-file/ for example code, it does not work out of the box for testing. One tries something like from click.testing import CliRunner
import pytest
from debug import app
@pytest.fixture()
def runner():
yield CliRunner()
def test_create(runner):
result = runner.invoke(app, ['create'])
assert result.exit_code == 0 but this fails with
So then you modify one line in the testing portion to be: result = runner.invoke(app, ['create'], prog_name="prog_name") and re-run with pytest, and you get a different error
and at this point, I'm not quite sure how to fix, in actuality. There seems to be poor support for Operating SystemmacOS Operating System DetailsNo response Typer Version0.7.0 Python VersionPython 3.8.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Somehow I missed the fact that I was using |
Beta Was this translation helpful? Give feedback.
Somehow I missed the fact that I was using
click.testing
and nottyper.testing
-- switching that fixes everything...