Skip to content

Commit 82929b6

Browse files
authored
Test example update (#236)
* Test example update because of @with_injector gone according to #146 Reported also on #220 * Cleanup
1 parent 395e7e8 commit 82929b6

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

docs/testing.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
Testing with Injector
22
=====================
33

4-
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::
4+
When you use unit test framework such as `unittest2` or `nose` you can also profit from `injector`. ::
55

66
import unittest
7-
from injector import Module, with_injector, inject
7+
from injector import Injector, Module
8+
89

910
class UsernameModule(Module):
1011
def configure(self, binder):
1112
binder.bind(str, 'Maria')
1213

14+
1315
class TestSomethingClass(unittest.TestCase):
14-
@with_injector(UsernameModule())
16+
1517
def setUp(self):
16-
pass
18+
self.__injector = Injector(UsernameModule())
1719

18-
@inject
19-
def test_username(self, username: str):
20+
def test_username(self):
21+
username = self.__injector.get(str)
2022
self.assertEqual(username, 'Maria')
2123

22-
**Each** method call re-initializes :class:`~injector.Injector` - if you want to you can also put :func:`~injector.with_injector` decorator on class constructor.
23-
24-
After such call all :func:`~injector.inject`-decorated methods will work just as you'd expect them to work.

0 commit comments

Comments
 (0)