Skip to content

Commit

Permalink
Add test for make_pass_decorator arg handling
Browse files Browse the repository at this point in the history
This adds a simple test case which ensures that `make_pass_decorator`
doesn't consume arguments if it's called out of order.
  • Loading branch information
sirosen committed Aug 11, 2018
1 parent 2069768 commit 0aeb6df
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,39 @@ def foo():
assert not result.exception
assert result.output == 'aha!\n'
assert called == [True]


def test_make_pass_decorator_args(runner):
"""
Test to check that make_pass_decorator doesn't consume arguments based on
invocation order.
"""
class Foo(object):
title = 'foocmd'

pass_foo = click.make_pass_decorator(Foo)

@click.group()
@click.pass_context
def cli(ctx):
ctx.obj = Foo()

@cli.command()
@click.pass_context
@pass_foo
def test1(foo, ctx):
click.echo(foo.title)

@cli.command()
@pass_foo
@click.pass_context
def test2(ctx, foo):
click.echo(foo.title)

result = runner.invoke(cli, ['test1'])
assert not result.exception
assert result.output == 'foocmd\n'

result = runner.invoke(cli, ['test2'])
assert not result.exception
assert result.output == 'foocmd\n'

0 comments on commit 0aeb6df

Please sign in to comment.