diff --git a/tests/unit/wiring/test_inject_and_wraps_decorator_py36.py b/tests/unit/wiring/test_inject_and_wraps_decorator_py36.py new file mode 100644 index 00000000..0c819143 --- /dev/null +++ b/tests/unit/wiring/test_inject_and_wraps_decorator_py36.py @@ -0,0 +1,49 @@ +"""Test that @functools.wraps decorator works properly with the wiring. + +See issue #453 for details: https://github.com/ets-labs/python-dependency-injector/issues/454 +""" + +import functools + +from dependency_injector.wiring import inject, Provide +from pytest import fixture + +from samples.wiring.container import Container + + +@fixture +def container(): + container = Container() + yield container + container.unwire() + + +def decorator1(func): + @functools.wraps(func) + @inject + def wrapper(value1: str = Provide[Container.config.value1]): + result = func() + return result + value1 + return wrapper + + +def decorator2(func): + @functools.wraps(func) + @inject + def wrapper(value2: str = Provide[Container.config.value2]): + result = func() + return result + value2 + return wrapper + + +@decorator1 +@decorator2 +def sample(): + return 2 + + +def test_wraps(container: Container): + container.wire(modules=[__name__]) + container.config.from_dict({"value1": 42, "value2": 15}) + + assert sample() == 2+42+15