I have the following code in test.py
:
import click
@click.command()
@click.option('--text', default='hello world', help='Text to display.')
def say(text):
print(text)
if __name__ == "__main__":
say()
If I call this in the command line, it works:
python test.py --text=hi!
>>hi!
If I want to test my code, I would use:
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(test.say, ['--text=blablabla'])
assert result.output == 'blablabla
This works too.
However, if I run my test through coverage.py, I see that the code under if __name__ == "__main__":
is not tested. Is there a way to achieve that?