File: test_setup_flow_example.py

package info (click to toggle)
codespeak-lib 0.9.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,212 kB
  • ctags: 5,409
  • sloc: python: 33,390; ansic: 961; xml: 582; makefile: 90
file content (42 lines) | stat: -rw-r--r-- 1,251 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def setup_module(module):
    module.TestStateFullThing.classcount = 0

class TestStateFullThing:
    def setup_class(cls):
        cls.classcount += 1

    def teardown_class(cls):
        cls.classcount -= 1

    def setup_method(self, method):
        self.id = eval(method.func_name[5:])

    def test_42(self):
        assert self.classcount == 1
        assert self.id == 42

    def test_23(self):
        assert self.classcount == 1
        assert self.id == 23

def teardown_module(module):
    assert module.TestStateFullThing.classcount == 0

""" For this example the control flow happens as follows::
    import test_setup_flow_example
    setup_module(test_setup_flow_example)
       setup_class(TestStateFullThing)
           instance = TestStateFullThing()
           setup_method(instance, instance.test_42)
              instance.test_42()
           setup_method(instance, instance.test_23)
              instance.test_23()
       teardown_class(TestStateFullThing)
    teardown_module(test_setup_flow_example)

Note that ``setup_class(TestStateFullThing)`` is called and not
``TestStateFullThing.setup_class()`` which would require you
to insert ``setup_class = classmethod(setup_class)`` to make
your setup function callable.
"""