只要通過由換行(\n
)加入字符串傳遞多個輸入:
import click
from click.testing import CliRunner
def test_prompts():
@click.command()
@click.option('--username', prompt=True)
@click.option('--password', prompt=True)
def test(username, password):
# download ..
click.echo('Download complete!')
# OR
#
# @click.command()
# def test():
# username = click.prompt('Username')
# password = click.prompt('Password', hide_input=True)
# # download ..
# click.echo('Download complete!')
runner = CliRunner()
result = runner.invoke(test, input='username\npassword\n') # <---
assert not result.exception
assert result.output.endswith('Download complete!\n')
if __name__ == '__main__':
test_prompts()
@StephenRauch,一個'input'參數,而不是一個'input'方法。在單擊文檔中查看[Input Streams](http://click.pocoo.org/5/testing/#input-streams)。 – falsetru
我的錯誤,我犯了一個錯誤,但自此糾正; input是clirunner的調用方法的一個參數 – jkarimi