I'm using click v8.1.3 and I'm trying to create some pytests, but I'm not getting my expected return_value
when using click.testing.CliRunner().invoke
import click.testing
import mycli
def test_return_ctx():
@mycli.cli.command()
def foo():
return "Potato"
runner = click.testing.CliRunner()
result = runner.invoke(mycli.cli, ["foo"])
assert result.return_value == "Potato" # this fails. b/c the actual value is None
I tried updating the root command to return some random value as well to see if we get a value there
# mycli
import click
@click.group()
def cli():
return "Potato"
But it didn't help. return_value
for the Result
object is still None
Am I misunderstanding how I should return a value from a command?
https://click.palletsprojects.com/en/8.1.x/api/#click.testing.Result.return_value
standalone_mode
toFalse
will makereturn_value
work since the documentation only mentions thatsystem.exit()
won't be called, but not that other stuff will start to work. – Outlaw