-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_setup_teardown.py
44 lines (30 loc) · 1.04 KB
/
test_setup_teardown.py
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
43
44
"""
pytest supports setup and teardown in much the same way
as unittest.TestCase, but you can also do it at the module level:
http://pytest.org/latest/xunit_setup.html#xunitsetup
(But, spoiler alert: you don't end up using this much because
pytest's fixture system is so amazing.)
Command:
py.test -v -s test_setup_teardown.py
"""
def setup_module(module):
print('\nsetting up module')
module.module_var = 'module'
def teardown_module(module):
print('tearing down module')
class TestSetup:
@classmethod
def setup_class(cls):
print('setting up class', cls.__name__)
cls.class_var = 'class'
@classmethod
def teardown_class(cls):
print('tearing down class', cls.__name__)
def setup_method(self, method):
print('\nsetting up method', method.__name__)
def teardown_method(self, method):
print('\ntearing down method', method.__name__)
def test_module_var(self):
assert module_var == 'module'
def test_class_var(self):
assert self.class_var == 'class'