Skip to content

PyTest won't inject fixtures into decorated functions in Python 2.7 #2782

Closed
@nonsleepr

Description

@nonsleepr

_pytest.compat.get_real_func doesn't work as expected in Python 2.7:

Example:

from _pytest.compat import get_real_func

import functools

def my_decorator(f):
    @functools.wraps(f)
    def wrapper(*args, **kwds):
        print('Calling decorated function')
        return f(*args, **kwds)
    return wrapper

#@my_decorator
def example():
    """Docstring"""
    print('Called example function')

decorated_example = my_decorator(example)

if get_real_func(decorated_example) is example:
    print('get_real_func works')
else:
    print('get_real_func fails')

Python 3.5 output:

$ python3.5 test.py
get_real_func works

Python 2.7 output:

$ python2.7 test.py
get_real_func fails

Tested with PyTest 3.0.6 though the same idea (isinstance(obj, functools.partial)) is attempted in master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: 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