diff --git a/docs/testing.rst b/docs/testing.rst index 568cbc2..c5cca33 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -1,24 +1,23 @@ Testing with Injector ===================== -When you use unit test framework such as `unittest2` or `nose` you can also profit from `injector`. However, manually creating injectors and test classes can be quite annoying. There is, however, `with_injector` method decorator which has parameters just as `Injector` construtor and installes configured injector into class instance on the time of method call:: +When you use unit test framework such as `unittest2` or `nose` you can also profit from `injector`. :: import unittest - from injector import Module, with_injector, inject + from injector import Injector, Module + class UsernameModule(Module): def configure(self, binder): binder.bind(str, 'Maria') - class TestSomethingClass(unittest.TestCase): - @with_injector(UsernameModule()) - def setUp(self): - pass - @inject - def test_username(self, username: str): + class TestSomethingClass(unittest.TestCase): + + def setUp(self): + self.__injector = Injector(UsernameModule()) + + def test_username(self): + username = self.__injector.get(str) self.assertEqual(username, 'Maria') -**Each** method call re-initializes :class:`~injector.Injector` - if you want to you can also put :func:`~injector.with_injector` decorator on class constructor. - -After such call all :func:`~injector.inject`-decorated methods will work just as you'd expect them to work.