When I test click, I understand the basic setup looks something like this:
import click
@click.command()
@click.argument('name')
def hello(name):
click.echo('Hello %s!' % name)
Test file
from click.testing import CliRunner
from hello import hello
def test_hello_world():
runner = CliRunner()
result = runner.invoke(hello, ['Peter'])
assert result.exit_code == 0
assert result.output == 'Hello Peter!\n'
However, if I use logging instead of print, I can't capture the output or check the return value of a command. For example:
import click
import logging as log
@click.command()
@click.argument('name')
def hello(name):
log.info('Hello %s!' % name)
return name
I can't check to see if that return value is correct without printing or click.echo'ing it.
Is there a way to check for return values or check output against logging using click?