Skip to content

Commit 1a79382

Browse files
authored
custom suite labels for pytest (fixes #46 via #395)
2 parents bb83304 + f5c9928 commit 1a79382

File tree

7 files changed

+83
-8
lines changed

7 files changed

+83
-8
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Custom suite
2+
____________
3+
4+
5+
>>> import allure
6+
7+
>>> @allure.parent_suite("parent suite name")
8+
>>> @allure.suite("suite name")
9+
>>> @allure.sub_suite("sub suite name")
10+
... def test_custom_suite():
11+
... pass
12+
13+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Module level custom suite
2+
-------------------------
3+
4+
>>> import allure
5+
6+
>>> pytestmark = allure.suite("module level suite name")
7+
8+
9+
>>> def test_module_level_custom_suite():
10+
... pass

allure-pytest/src/utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
ALLURE_DESCRIPTION_HTML = 'allure_description_html'
1616
ALLURE_LABEL_PREFIX = 'allure_label'
1717
ALLURE_LINK_PREFIX = 'allure_link'
18-
ALLURE_UNIQUE_LABELS = ['severity', 'thread', 'host']
18+
ALLURE_UNIQUE_LABELS = [
19+
LabelType.SEVERITY,
20+
LabelType.FRAMEWORK,
21+
LabelType.HOST,
22+
LabelType.SUITE,
23+
LabelType.PARENT_SUITE,
24+
LabelType.SUB_SUITE
25+
]
1926

2027

2128
def get_marker_value(item, keyword):
@@ -112,8 +119,14 @@ def allure_suite_labels(item):
112119
file_name, path = islice(chain(reversed(head.rsplit('/', 1)), [None]), 2)
113120
module = file_name.split('.')[0]
114121
package = path.replace('/', '.') if path else None
115-
pairs = zip([LabelType.PARENT_SUITE, LabelType.SUITE, LabelType.SUB_SUITE], [package, module, clazz])
116-
return [(name, value) for name, value in pairs if value is not None]
122+
pairs = dict(zip([LabelType.PARENT_SUITE, LabelType.SUITE, LabelType.SUB_SUITE], [package, module, clazz]))
123+
labels = dict(allure_labels(item))
124+
default_suite_labels = []
125+
for suite_label in pairs.keys():
126+
if suite_label not in labels.keys():
127+
default_suite_labels.append((suite_label, pairs[suite_label]))
128+
129+
return default_suite_labels
117130

118131

119132
def escape_name(name):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
""" ./examples/label/suite/custom_suite.rst """
2+
3+
from hamcrest import assert_that
4+
from allure_commons_test.report import has_test_case
5+
from allure_commons_test.label import has_suite, has_parent_suite, has_sub_suite
6+
7+
8+
def test_custom_suite(executed_docstring_path):
9+
assert_that(executed_docstring_path.allure_report,
10+
has_test_case("test_custom_suite",
11+
has_suite("suite name"),
12+
has_parent_suite("parent suite name"),
13+
has_sub_suite("sub suite name")
14+
)
15+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
""" ./examples/label/suite/module_level_custom_suite.rst """
2+
3+
from hamcrest import assert_that
4+
from allure_commons_test.report import has_test_case
5+
from allure_commons_test.label import has_suite
6+
7+
8+
def test_module_custom_suite(executed_docstring_path):
9+
assert_that(executed_docstring_path.allure_report,
10+
has_test_case("test_module_level_custom_suite",
11+
has_suite("module level suite name"),
12+
)
13+
)

allure-python-commons/allure.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from allure_commons._allure import label
44
from allure_commons._allure import severity
55
from allure_commons._allure import tag
6+
from allure_commons._allure import suite, parent_suite, sub_suite
67
from allure_commons._allure import epic, feature, story
78
from allure_commons._allure import link, issue, testcase
89
from allure_commons._allure import Dynamic as dynamic
@@ -18,21 +19,19 @@
1819
'description_html',
1920
'label',
2021
'severity',
22+
'suite',
23+
'parent_suite',
24+
'sub_suite',
2125
'tag',
2226
'epic',
2327
'feature',
2428
'story',
25-
2629
'link',
2730
'issue',
2831
'testcase',
29-
3032
'step',
31-
3233
'dynamic',
33-
3434
'severity_level',
35-
3635
'attach',
3736
'attachment_type'
3837
]

allure-python-commons/src/_allure.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ def story(*stories):
4747
return label(LabelType.STORY, *stories)
4848

4949

50+
def suite(suite_name):
51+
return label(LabelType.SUITE, suite_name)
52+
53+
54+
def parent_suite(parent_suite_name):
55+
return label(LabelType.PARENT_SUITE, parent_suite_name)
56+
57+
58+
def sub_suite(sub_suite_name):
59+
return label(LabelType.SUB_SUITE, sub_suite_name)
60+
61+
5062
def tag(*tags):
5163
return label(LabelType.TAG, *tags)
5264

0 commit comments

Comments
 (0)