You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the Typer documentation, with the integrated search.
I already searched in Google "How to X in Typer" and didn't find any information.
I already read and followed all the tutorials in the docs and didn't find an answer.
I already checked if it is not related to Typer but to Click.
Commit to Help
I commit to help with one of those options 👆
Example Code
conftest.py
importpytestfromtyper.testingimportCliRunnerfromjuju_doctor.mainimportapp@pytest.fixture(scope="function") # I was hoping this would work, but doesn'tdefrunner():
returnCliRunner()
@pytest.fixture(scope="function") # I was hoping this would work, but doesn'tdefapp_fixture():
returnapp
my-test.py
importjsondeftest_1(runner, app_fixture):
test_args= ["example"]
result=runner.invoke(app_fixture, test_args)
assertlen(json.loads(result.stdout)["Results"]["children"]) ==1# Now has len == 1deftest_2(runner, app_fixture):
test_args= ["example"]
result=runner.invoke(app_fixture, test_args)
assertlen(json.loads(result.stdout)["Results"]["children"]) ==1# Now has len == 2
Description
I have an app and I want to add tests for my app. With many pytests using typer.testing.CliRunner.invoke -> Result, the state grows, and I cannot figure out why! I tried to use a fixture, scoped to function, for my imported juju_doctor.main.app and typer.testing.CliRunner. This did not work 🥀
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
conftest.py
my-test.py
Description
I have an app and I want to add tests for my app. With many pytests using
typer.testing.CliRunner.invoke -> Result
, the state grows, and I cannot figure out why! I tried to use a fixture, scoped to function, for my importedjuju_doctor.main.app
andtyper.testing.CliRunner
. This did not work 🥀Operating System
Linux
Operating System Details
Ubuntu 24.04 LTS
Typer Version
0.15.3
Python Version
3.10.0
Additional Context
Here is my app if you are curious:
Beta Was this translation helpful? Give feedback.
All reactions