Skip to content

Instantly share code, notes, and snippets.

@lewoudar
Created November 30, 2020 18:02
Show Gist options
  • Save lewoudar/62fd2c5dbf5d052b15737e9e6e118a80 to your computer and use it in GitHub Desktop.
Save lewoudar/62fd2c5dbf5d052b15737e9e6e118a80 to your computer and use it in GitHub Desktop.
An example of how to test a cli application with click
from click.testing import CliRunner
from scripts.pycat import cli
def test_pycat(tmp_path):
hello_file = tmp_path / 'hello.txt'
hello_file.write_text('hello world!')
runner = CliRunner()
result = runner.invoke(cli, [f'{hello_file.resolve()}'])
assert 0 == result.exit_code
assert 'hello world!\n' == result.output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment