Should be able to be turned off when testing
Closed this issue · 4 comments
What I am thinking is,
- When turned off, all
ioc.IN
should be replaced byNone
if not provided. - Should work with mock and other test framework. (at least pyjazz)
Anything to add?
That would be quite simple:
import ioc
ioc.EnableTestMode() # Essentially just sets IN to None
import subject
But what's the issue with the current approach? I don't think None
is an acceptable value for injected objects. Since you can override injected values with the call's args, I don't even see a need to change the behavior of the injection, but only warn if a value is being injected in test mode as it is even conceivable that injections would be desired in test mode. I think that this makes more sense than injecting None
s. It's more explicit and clearer than getting AttributeError
s on None
s.
import ioc
import subject
def setUp():
ioc.EnableTestMode() # Enables injection checking + creates TestInjectionsOK.
class Test:
def testA(self):
subject.foo(a=3, b=4) # All injections are injected, OK
def testB(self):
with self.assertRaises(InjectionDuringTestError):
subject.foo(a=3) # injected b is not overridden, so throws
def testC(self):
with ioc.TestInjectionsOK:
subject.foo(a=3) # OK to inject b
I like the idea of EnableTestMode
and do all the checking and what not. A little bit hesitate on the TestInjectionsOK
. Isn't that equal to not calling EnableTestMode
?
Yes, it would be equivalent to temporarily turning off the checks for a
certain injection(s). But I'm totally cool with leaving it out, especially
until we see the need.
On Jul 23, 2013 6:05 PM, "Zak Tsai" notifications@github.com wrote:
I like the idea of EnableTestMode and do all the checking and what not. A
little bit hesitate on the TestInjectionsOK. Isn't that equal to not
calling EnableTestMode?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-21457495
.
Alternatively, a la Guice, you could pull an injection out of the scope for use in your tests if you want and that could be allowed.