Skip to content

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

Closed
@pytestbot

Description

@pytestbot

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.


Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions