Skip to content

Commit ef8d1f4

Browse files
authored
Add missing functions in dynamic package (#703)
* add missing labels in dynamic package * fix test_parametrized_dynamic_labels
1 parent d0415af commit ef8d1f4

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

allure-pytest/examples/label/bdd/dynamic_bdd_label.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@ Dynamic BDD labels
55
>>> import pytest
66

77
>>> @allure.feature('first feature')
8-
... def test_dynamic_feature():
8+
... @allure.epic('first epic')
9+
... @allure.story('first story')
10+
... def test_dynamic_labels():
911
... allure.dynamic.feature('second feature')
12+
... allure.dynamic.epic('second epic')
13+
... allure.dynamic.story('second story')
1014

11-
>>> @pytest.mark.parametrize('feature', ['first feature', 'second feature'])
12-
... def test_parametrized_dynamic_feature(feature):
15+
>>> @pytest.mark.parametrize('feature, epic, story', [('first feature', 'first epic', 'first story'),
16+
... ('second feature', 'second epic', 'second story')])
17+
... def test_parametrized_dynamic_labels(feature, epic, story):
1318
... allure.dynamic.feature(feature)
19+
... allure.dynamic.epic(epic)
20+
... allure.dynamic.story(story)
21+
22+
>>> def test_multiple_dynamic_labels():
23+
... allure.dynamic.feature('first feature', 'second feature')
24+
... allure.dynamic.epic('first epic', 'second epic')
25+
... allure.dynamic.story('first story', 'second story')

allure-pytest/test/acceptance/label/bdd/dynamic_bdd_label_test.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,44 @@
33
import pytest
44
from hamcrest import assert_that
55
from allure_commons_test.report import has_test_case
6-
from allure_commons_test.label import has_feature
6+
from allure_commons_test.label import has_feature, has_epic, has_story
77

88

9-
def test_dynamic_feature(executed_docstring_path):
9+
def test_dynamic_labels(executed_docstring_path):
1010
assert_that(executed_docstring_path.allure_report,
11-
has_test_case("test_dynamic_feature",
11+
has_test_case("test_dynamic_labels",
1212
has_feature("first feature"),
13-
has_feature("second feature")
13+
has_feature("second feature"),
14+
has_epic("first epic"),
15+
has_epic("second epic"),
16+
has_story("first story"),
17+
has_story("second story"),
1418
)
1519
)
1620

1721

18-
@pytest.mark.parametrize("feature", ["first feature", "second feature"])
19-
def test_parametrized_dynamic_feature(executed_docstring_path, feature):
22+
@pytest.mark.parametrize("feature, epic, story", [("first feature", "first epic", "first story"),
23+
("second feature", "second epic", "second story")])
24+
def test_parametrized_dynamic_labels(executed_docstring_path, feature, epic, story):
2025
assert_that(executed_docstring_path.allure_report,
21-
has_test_case("test_parametrized_dynamic_feature[{feature}]".format(feature=feature),
26+
has_test_case("test_parametrized_dynamic_labels[{feature}-{epic}-{story}]".format(feature=feature,
27+
epic=epic,
28+
story=story),
2229
has_feature(feature),
30+
has_epic(epic),
31+
has_story(story),
32+
)
33+
)
34+
35+
36+
def test_multiple_dynamic_labels(executed_docstring_path):
37+
assert_that(executed_docstring_path.allure_report,
38+
has_test_case("test_multiple_dynamic_labels",
39+
has_feature("first feature"),
40+
has_feature("second feature"),
41+
has_epic("first epic"),
42+
has_epic("second epic"),
43+
has_story("first story"),
44+
has_story("second story"),
2345
)
2446
)

allure-pytest/test/integration/allure_ee/set_testcase_id_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ def test_set_testcase_id_label(executed_docstring_source):
1616
has_label("as_id", 123),
1717
)
1818
)
19+
20+
21+
def test_set_dynamic_testcase_id_label(executed_docstring_source):
22+
"""
23+
>>> import allure
24+
25+
>>> def test_allure_ee_id_dynamic_label_example():
26+
... allure.dynamic.id(345)
27+
"""
28+
assert_that(executed_docstring_source.allure_report,
29+
has_test_case("test_allure_ee_id_dynamic_label_example",
30+
has_label("as_id", 345),
31+
)
32+
)

allure-python-commons/src/_allure.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def label(label_type, *labels):
108108
def severity(severity_level):
109109
Dynamic.label(LabelType.SEVERITY, severity_level)
110110

111+
@staticmethod
112+
def epic(*epics):
113+
Dynamic.label(LabelType.EPIC, *epics)
114+
111115
@staticmethod
112116
def feature(*features):
113117
Dynamic.label(LabelType.FEATURE, *features)
@@ -120,6 +124,10 @@ def story(*stories):
120124
def tag(*tags):
121125
Dynamic.label(LabelType.TAG, *tags)
122126

127+
@staticmethod
128+
def id(id):
129+
Dynamic.label(LabelType.ID, id)
130+
123131
@staticmethod
124132
def link(url, link_type=LinkType.LINK, name=None):
125133
plugin_manager.hook.add_link(url=url, link_type=link_type, name=name)

0 commit comments

Comments
 (0)