-
CLIの私の理解は、ターミナルからうつコマンドだと思っていましたが、pythonでいう(flaskでいう)CLIは、また違った意味のようで、コマンドが以下のURL先のようにつくれる?!もの?例えば、Click。。。少なく以下も文脈でのCLIが何を意味しているのか理解ができずにいます。
-
さらに、なぜ、ターミナル上で使うコマンドをつくったとしてわざわざそれをテストする必要性がでてくる意味がわかりません。仮に、必要があったとして、test_cli_runner() を実行してCliRunnerをわざわざ作成する意味がわからずにいます。
http://flask.pocoo.org/docs/1.0/testing/#testing-cli
Testing CLI Commands Click comes with utilities for testing your CLI commands. A CliRunner runs commands in isolation and captures the output in a Result object. Flask provides test_cli_runner() to create a FlaskCliRunner that passes the Flask app to the CLI automatically. Use its invoke() method to call commands in the same way they would be called from the command line. import click @app.cli.command('hello') @click.option('--name', default='World') def hello_command(name) click.echo(f'Hello, {name}!') def test_hello(): runner = app.test_cli_runner() # invoke the command directly result = runner.invoke(hello_command, ['--name', 'Flask']) assert 'Hello, Flask' in result.output # or by name result = runner.invoke(args=['hello']) assert 'World' in result.output In the example above, invoking the command by name is useful because it verifies that the command was correctly registered with the app. If you want to test how your command parses parameters, without running the command, use its make_context() method. This is useful for testing complex validation rules and custom types.
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/12 10:21
2018/08/12 10:30