modern-python / that-depends

DI-framework, inspired by python-dependency-injector, but without wiring. Python 3.12 is supported
https://that-depends.readthedocs.io/
MIT License
156 stars 12 forks source link

Why does redefining an argument raise an error? #49

Closed aballet closed 3 months ago

aballet commented 3 months ago

Hello,

I'm wondering why the re-definition of an argument raises an error?

I have this use case in mind: I find it elegant to inject a provider in a method's arguments, but I would love to override it in my unit tests by simply giving a mock as an argument. So far, I was able to do that with dependency-injector which I'm trying to replace, so I was wondering if I was missing the reason behind this error raising?

I'm thinking about defining my own inject to bypass this behavior; maybe it could be a parameter of the decorator?

Adrien.

lesnik512 commented 3 months ago

Hello, Adrien

But why not to use overriding? In this case I'm thinking about "The Zen of Python":

There should be one-- and preferably only one --obvious way to do it.

And mocking through arguments seems like another not very obvious way to mock something.

aballet commented 3 months ago

Hey, thank you for the quick answer.

It's a valid point indeed, I will refactor my tests a bit to work with overriding.