Skip to content

Commit

Permalink
Merge pull request #999 from kporangehat/invoke_with_prog_name
Browse files Browse the repository at this point in the history
Fix #616: allow setting prog_name as extra in CliRunner.invoke
  • Loading branch information
Dan Sully authored May 14, 2018
2 parents 43cb986 + 2bc3b2c commit 467fb8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions click/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,12 @@ def invoke(self, cli, args=None, input=None, env=None,
args = shlex.split(args)

try:
cli.main(args=args or (),
prog_name=self.get_default_prog_name(cli), **extra)
prog_name = extra.pop("prog_name")
except KeyError:
prog_name = self.get_default_prog_name(cli)

try:
cli.main(args=args or (), prog_name=prog_name, **extra)
except SystemExit as e:
exc_info = sys.exc_info()
exit_code = e.code
Expand Down
11 changes: 11 additions & 0 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,14 @@ def cli_args(foo):
result = runner.invoke(cli_args, args=args)
assert result.exit_code == 0
assert result.output == expected_output


def test_setting_prog_name_in_extra():
@click.command()
def cli():
click.echo("ok")

runner = CliRunner()
result = runner.invoke(cli, prog_name="foobar")
assert not result.exception
assert result.output == 'ok\n'

0 comments on commit 467fb8d

Please sign in to comment.