forked from allure-framework/allure-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_allure.py
More file actions
147 lines (97 loc) · 4.05 KB
/
_allure.py
File metadata and controls
147 lines (97 loc) · 4.05 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from functools import wraps
from allure_commons._core import plugin_manager
from allure_commons.types import LabelType, LinkType
from allure_commons.utils import uuid4
from allure_commons.utils import func_parameters
def safely(result):
if result:
return result[0]
else:
def dummy(function):
return function
return dummy
def label(label_type, *labels):
return safely(plugin_manager.hook.decorate_as_label(label_type=label_type, labels=labels))
def severity(severity_level):
return label(LabelType.SEVERITY, severity_level)
def epic(*epics):
return label(LabelType.EPIC, *epics)
def feature(*features):
return label(LabelType.FEATURE, *features)
def story(*stories):
return label(LabelType.STORY, *stories)
def tag(*tags):
return label(LabelType.TAG, *tags)
def link(url, link_type=LinkType.LINK, name=None):
return safely(plugin_manager.hook.decorate_as_link(url=url, link_type=link_type, name=name))
def issue(url, name=None):
return link(url, link_type=LinkType.ISSUE, name=name)
def testcase(url, name=None):
return link(url, link_type=LinkType.TEST_CASE, name=name)
class Dynamic(object):
@staticmethod
def label(label_type, *labels):
plugin_manager.hook.add_label(label_type=label_type, labels=labels)
@staticmethod
def severity(severity_level):
Dynamic.label(LabelType.SEVERITY, severity_level)
@staticmethod
def feature(*features):
Dynamic.label(LabelType.FEATURE, *features)
@staticmethod
def story(*stories):
Dynamic.label(LabelType.STORY, *stories)
@staticmethod
def tag(*tags):
Dynamic.label(LabelType.TAG, *tags)
@staticmethod
def link(url, link_type=LinkType.LINK, name=None):
plugin_manager.hook.add_link(url=url, link_type=link_type, name=name)
@staticmethod
def issue(url, name=None):
Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name)
@staticmethod
def testcase(url, name=None):
Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name)
def step(title):
if callable(title):
return StepContext(title.__name__, [])(title)
else:
return StepContext(title, [])
class StepContext:
def __init__(self, title, params):
self.title = title
self.params = params
self.uuid = uuid4()
def __enter__(self):
plugin_manager.hook.start_step(uuid=self.uuid, title=self.title, params=self.params)
def __exit__(self, exc_type, exc_val, exc_tb):
plugin_manager.hook.stop_step(uuid=self.uuid, title=self.title, exc_type=exc_type, exc_val=exc_val,
exc_tb=exc_tb)
def __call__(self, func):
@wraps(func)
def impl(*a, **kw):
__tracebackhide__ = True
params = func_parameters(func, *a, **kw)
with StepContext(self.title.format(*a, **kw), params):
return func(*a, **kw)
return impl
class Attach(object):
def __call__(self, body, name=None, attachment_type=None, extension=None):
plugin_manager.hook.attach_data(body=body, name=name, attachment_type=attachment_type, extension=extension)
def file(self, source, name=None, attachment_type=None, extension=None):
plugin_manager.hook.attach_file(source=source, name=name, attachment_type=attachment_type, extension=extension)
attach = Attach()
class fixture(object):
def __init__(self, fixture_function, parent_uuid=None, name=None):
self._fixture_function = fixture_function
self._parent_uuid = parent_uuid
self._name = name if name else fixture_function.__name__
self._uuid = uuid4()
def __call__(self, *args, **kwargs):
with self:
return self._fixture_function(*args, **kwargs)
def __enter__(self):
plugin_manager.hook.start_fixture(parent_uuid=self._parent_uuid, uuid=self._uuid, name=self._name)
def __exit__(self, exc_type, exc_val, exc_tb):
plugin_manager.hook.stop_fixture(uuid=self._uuid, exc_type=exc_type, exc_val=exc_val, exc_tb=exc_tb)