Debian Codegraph @

doc/en/example/assertion/test_setup_flow_example.py

raw
1 from __future__ import annotations
2
3
4 def setup_module(module):
5 module.TestStateFullThing.classcount = 0
6
7
8 class TestStateFullThing:
9 def setup_class(cls):
10 cls.classcount += 1
11
12 def teardown_class(cls):
13 cls.classcount -= 1
14
15 def setup_method(self, method):
16 self.id = eval(method.__name__[5:])
17
18 def test_42(self):
19 assert self.classcount == 1
20 assert self.id == 42
21
22 def test_23(self):
23 assert self.classcount == 1
24 assert self.id == 23
25
26
27 def teardown_module(module):
28 assert module.TestStateFullThing.classcount == 0
29
30
31 """ For this example the control flow happens as follows::
32 import test_setup_flow_example
33 setup_module(test_setup_flow_example)
34 setup_class(TestStateFullThing)
35 instance = TestStateFullThing()
36 setup_method(instance, instance.test_42)
37 instance.test_42()
38 setup_method(instance, instance.test_23)
39 instance.test_23()
40 teardown_class(TestStateFullThing)
41 teardown_module(test_setup_flow_example)
42
43 Note that ``setup_class(TestStateFullThing)`` is called and not
44 ``TestStateFullThing.setup_class()`` which would require you
45 to insert ``setup_class = classmethod(setup_class)`` to make
46 your setup function callable.
47 """