Testing Click Applications
https://click.palletsprojects.com/en/8.1.x/testing/
#Click_Documentation
click.testing
helps you invoke command line applications and check their behavior.
Basic Testing
CliRunner.invoke
The return value is a Result object, which has the captured output data, exit code, and optional exception attached:
helloコマンドをinvokeする例
invokeに渡す配列は文字列のリスト(=引数リスト)
For subcommand testing, a subcommand name must be specified in the args parameter of CliRunner.invoke() method
invokeの第1引数にはGroupを渡す
文字列のリスト(args引数)にサブコマンド名を渡す
File System Isolation
CliRunner.isolated_filesystem
setting the current working directory to a new, empty folder.
catコマンドのテスト
入力するファイルをテストコード実行で動的に作る(writeしている)
IMO:フィクスチャとしてファイルを用意したほうがわかりやすいのではないか
temp_dir引数にpytestのtmp_pathフィクスチャを渡す例
This is useful to integrate with a framework like Pytest that manages temporary files.
👉How to use temporary directories and files in tests
Input Streams
CliRunner.invokeのinput引数