Entering the code below in test_greet.py :
import click from click.testing import CliRunner def test_greet(): @click.command() @click.argument('name') def greet(name): click.echo('Hello %s' % name) runner = CliRunner() result = runner.invoke(greet, ['Sam']) assert result.output == 'Hello Sam\n' if __name__ == '__main__': test_greet()
If just called with python test_greet.py , the tests pass and nothing is displayed. When used as part of a test, it works as expected. For example, nosetests test_greet.py returns
. ---------------------------------------------------------------------- Ran 1 test in 0.002s OK
source share