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

Different interaction between fixtures, functools.wraps and default arguments in python 2 and 3 #677

Closed
pytestbot opened this issue Feb 8, 2015 · 4 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: David MacIver (BitBucket: david_maciver_, GitHub: david_maciver_)


#!python

from functools import wraps


def add_default(f):
    @wraps(f)
    def hello(x=1):
        return f(x)
    return hello


@add_default
def test_hello(x):
    assert x == 1

In python 2 the addition of the default works: The test is called with x=1. In python 3 this looks for a fixture and errors with fixture 'x' not found.

Additionally, if I remove the wraps this works in both versions.

I'm not sure what the intended correct behaviour is, but having the behaviour be different between 2 or 3 sounds like a bug regardless of which one is correct.


@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@RonnyPfannschmidt
Copy link
Member

python3 is correct, python2 has a bug in functools.wraps

@DRMacIver where you the reporter?

@DRMacIver
Copy link

Yep, that was me. I'm no longer directly affected by this issue because I have a huge elaborate function wrapping infrastructure to work around it and some related things now. :-)

@Zearin
Copy link
Contributor

Zearin commented Feb 2, 2016

Yep, that was me. I'm no longer directly affected by this issue because I have a huge elaborate function wrapping infrastructure to work around it and some related things now. :-)

Would you be willing to link to your elaborate function wrapping infrastructure? Perhaps it could help the devs fix this bug. :)

@RonnyPfannschmidt
Copy link
Member

closing this one as user code bug, python2 has a broken functools.wraps

jeffwidman added a commit to dpkp/kafka-python that referenced this issue Aug 22, 2019
Now that we are using `pytest`, there is no need for a custom decorator
because we can use `pytest.mark.skipif()`.

This makes the code significantly simpler. In particular, dropping the
custom `@kafka_versions()` decorator is necessary because it uses
`func.wraps()` which doesn't play nice with `pytest` fixtures:
- pytest-dev/pytest#677
- https://stackoverflow.com/a/19614807/770425

So this is a pre-requisite to migrating some of those tests to using
pytest fixtures.
jeffwidman added a commit to dpkp/kafka-python that referenced this issue Aug 22, 2019
Now that we are using `pytest`, there is no need for a custom decorator
because we can use `pytest.mark.skipif()`.

This makes the code significantly simpler. In particular, dropping the
custom `@kafka_versions()` decorator is necessary because it uses
`func.wraps()` which doesn't play nice with `pytest` fixtures:
- pytest-dev/pytest#677
- https://stackoverflow.com/a/19614807/770425

So this is a pre-requisite to migrating some of those tests to using
pytest fixtures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

4 participants