#!/usr/bin/env python # coding: utf-8 # # Using [`click`](https://github.com/pallets/click) interactively # # We all know that `argparse` sucks, and `click` is a common replacement. # # See the `click` documentation for the more information about [__Complex Arguments__](http://click.pocoo.org/5/complex/#calling-convention). # In[1]: import click # In[2]: @click.command() @click.option('--count', default=1, help='Number of greetings.') @click.option('--name', prompt='Your name', help='The person to greet.') def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for x in range(count): print('Hello! %s!' % name) # * Create an a `click.Context` # In[6]: from pytest import fixture ctx = fixture(lambda: click.Context(hello)) # * `click.Context.invoke` the command. # In[10]: _test_interactive_invocation = lambda ctx: ctx.invoke(hello, name="❤ deathbeds") __name__ == '__main__' and _test_interactive_invocation(ctx())