This commit is contained in:
Roman Mogylatov 2022-07-25 17:35:04 -04:00
parent 6554b25431
commit 957a467229

View File

@ -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