python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Create a way to detect a provided argument object from an injected function in a unit test

Open gencurrent opened this issue 2 years ago • 0 comments
trafficstars

I use simple Python unit tests. Currently I do not see any way to detect what object is provided within an injected function argument defaulted with Provide. E.g. Function declaration

@inject
def the_function(
    *args,
    provided_object: CustomClass = Provide["provide_objects"],
) -> None:
    ... # Body

Then after the wiring I want to ensure a correct class is wired and provided before it fails at a prod system

    def test__di (self):
        obj = dependency_injector.get_provided_kwargs(the_function)["provided_object"]
        self.assertInstance(obj, CustomClass)

If there is already a way to find out the provided object, I would be grateful for the response about that.

gencurrent avatar Mar 21 '23 19:03 gencurrent