Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't arbitrarily strip an argument from make_pass_decorator #787

Merged
merged 2 commits into from Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion click/decorators.py
Expand Up @@ -61,7 +61,7 @@ def new_func(*args, **kwargs):
raise RuntimeError('Managed to invoke callback without a '
'context object of type %r existing'
% object_type.__name__)
return ctx.invoke(f, obj, *args[1:], **kwargs)
return ctx.invoke(f, obj, *args, **kwargs)
return update_wrapper(new_func, f)
return decorator

Expand Down
36 changes: 36 additions & 0 deletions tests/test_context.py
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'