Skip to content
Myr

Add note about subcommands testing. Closes #377

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Testing `Click` Applications documentation isn't clear enough for cases involving subcommands. I have added a note about subcommand testing, as well as a code example.

authored by Alexander Pyatkin · committed by Alexander Pyatkin · parent 750ba75 · Browse files · 1 file+23 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−0 removed

  • other:+23 added−0 removed

1 file+23 added−0 removed

modified:docs/testing.rst+23 added
36 unmodified lines
37 result = runner.invoke(hello, ['Peter'])38 assert result.exit_code == 039 assert result.output == 'Hello Peter!\n'4041For subcommand testing, a subcommand name must be specified in the `args` parameter of :meth:`CliRunner.invoke` method.4243Example::4445 import click46 from click.testing import CliRunner47 48 def test_sync():49 @click.group()50 @click.option('--debug/--no-debug', default=False)51 def cli(debug):52 click.echo('Debug mode is %s' % ('on' if debug else 'off')) 53 54 @cli.command()55 def sync():56 click.echo('Syncing')57 58 runner = CliRunner()59 result = runner.invoke(cli, ['--debug', 'sync'])60 assert result.exit_code == 061 assert 'Debug mode is on' in result.output62 assert 'Syncing' in result.output6364File System Isolation65---------------------6667For basic command line tools that want to operate with the file system, the
46 unmodified lines