Skip to content
Discussion options

You must be logged in to vote

Your script exits before getting to the last print because the app() invocation raises a SystemExit exception, since it is expecting to be the last thing run in the process.

You could try to catch the exception and access the exit code like this:

try:
    app()
except SystemExit as e:
   print(f"Exited with exit code {e.code}")

But a better approach might be to use the CliRunner utility from typer.testing, which is designed to do basically what you are trying to do: run a typer app from the context of a longer-running piece of code. It can also capture the output for you, which might be cleaner than patching stderr and stdout.

You can read more about CliRunner here and here

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@YuriiMotov
Comment options

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants