forked from netanelrevah/tstcls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtstcls.py
50 lines (37 loc) · 1.35 KB
/
tstcls.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
45
46
47
48
49
50
import inspect
from pytest import fixture
__all__ = ["TestClassBase"]
class TestClassBase(object):
@classmethod
def find_fixtures(cls, func, request):
fixtures = {}
arg_spec = inspect.getfullargspec(func)
for index, arg in enumerate(arg_spec.args):
if index == 0 and arg in ["self", "cls"]:
continue
fixtures[arg] = request.getfixturevalue(arg)
return fixtures
@fixture(autouse=True, scope="class")
def init_class(self, request):
setup_fixtures = self.find_fixtures(self.setup_test_class, request)
teardown_fixtures = self.find_fixtures(self.teardown_test_class, request)
self.__class__.setup_test_class(**setup_fixtures)
yield
self.__class__.teardown_test_class(**teardown_fixtures)
@fixture(autouse=True)
def init(self, request):
setup_fixtures = self.find_fixtures(self.setup_test, request)
teardown_fixtures = self.find_fixtures(self.teardown_test, request)
self.setup_test(**setup_fixtures)
yield
self.teardown_test(**teardown_fixtures)
def setup_test(self, **fixtures):
pass
def teardown_test(self, **fixtures):
pass
@classmethod
def setup_test_class(cls, **fixtures):
pass
@classmethod
def teardown_test_class(cls, **fixtures):
pass