只要通过由换行(\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