Support return value when using CliRunner #559
-
First Check
Commit to Help
Example Codeimport typer
from typer.testing import CliRunner
app = typer.Typer()
@app.command()
def main():
print("hello from stdout")
return "hello from return_value"
runner = CliRunner()
result = runner.invoke(app)
result.exit_code
#> 0
result.stdout
#> 'hello from stdout\n'
result.return_value
result.return_value is None
#> True Created at 2023-02-22 17:13:45 EST by reprexlite v1.0.0 DescriptionClick v8.0.0 introduced the ability to capture the return value of a Click command when using Click's CliRunner to the When using Typer's CliRunner, the return value seems to get lost and is not captured. References: Operating SystemmacOS Operating System DetailsNo response Typer VersionTyper 0.7.0 Python VersionPython 3.9.16 Additional ContextClick 8.1.3 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
What about this? This would be very helpful! I'm in version 0.9.0 but still any update about this. @jayqi Have you find any shortcut to solve the issue? |
Beta Was this translation helpful? Give feedback.
-
Just found how to fix this just run the def test_app():
result = runner.invoke(
app, ["command"], standalone_mode=False
)
assert result.exit_code == 0
print(result.return_value) # print the result and not get None Idea by this |
Beta Was this translation helpful? Give feedback.
Just found how to fix this just run the
invoke
method withstandalone_mode=False
Idea by this