Skip to content

Commit

Permalink
Add missing functions in dynamic package (allure-framework#703)
Browse files Browse the repository at this point in the history
* add missing labels in dynamic package

* fix test_parametrized_dynamic_labels
  • Loading branch information
daserok authored Nov 6, 2022
1 parent d0415af commit ef8d1f4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
18 changes: 15 additions & 3 deletions allure-pytest/examples/label/bdd/dynamic_bdd_label.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ Dynamic BDD labels
>>> import pytest

>>> @allure.feature('first feature')
... def test_dynamic_feature():
... @allure.epic('first epic')
... @allure.story('first story')
... def test_dynamic_labels():
... allure.dynamic.feature('second feature')
... allure.dynamic.epic('second epic')
... allure.dynamic.story('second story')

>>> @pytest.mark.parametrize('feature', ['first feature', 'second feature'])
... def test_parametrized_dynamic_feature(feature):
>>> @pytest.mark.parametrize('feature, epic, story', [('first feature', 'first epic', 'first story'),
... ('second feature', 'second epic', 'second story')])
... def test_parametrized_dynamic_labels(feature, epic, story):
... allure.dynamic.feature(feature)
... allure.dynamic.epic(epic)
... allure.dynamic.story(story)

>>> def test_multiple_dynamic_labels():
... allure.dynamic.feature('first feature', 'second feature')
... allure.dynamic.epic('first epic', 'second epic')
... allure.dynamic.story('first story', 'second story')
36 changes: 29 additions & 7 deletions allure-pytest/test/acceptance/label/bdd/dynamic_bdd_label_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,44 @@
import pytest
from hamcrest import assert_that
from allure_commons_test.report import has_test_case
from allure_commons_test.label import has_feature
from allure_commons_test.label import has_feature, has_epic, has_story


def test_dynamic_feature(executed_docstring_path):
def test_dynamic_labels(executed_docstring_path):
assert_that(executed_docstring_path.allure_report,
has_test_case("test_dynamic_feature",
has_test_case("test_dynamic_labels",
has_feature("first feature"),
has_feature("second feature")
has_feature("second feature"),
has_epic("first epic"),
has_epic("second epic"),
has_story("first story"),
has_story("second story"),
)
)


@pytest.mark.parametrize("feature", ["first feature", "second feature"])
def test_parametrized_dynamic_feature(executed_docstring_path, feature):
@pytest.mark.parametrize("feature, epic, story", [("first feature", "first epic", "first story"),
("second feature", "second epic", "second story")])
def test_parametrized_dynamic_labels(executed_docstring_path, feature, epic, story):
assert_that(executed_docstring_path.allure_report,
has_test_case("test_parametrized_dynamic_feature[{feature}]".format(feature=feature),
has_test_case("test_parametrized_dynamic_labels[{feature}-{epic}-{story}]".format(feature=feature,
epic=epic,
story=story),
has_feature(feature),
has_epic(epic),
has_story(story),
)
)


def test_multiple_dynamic_labels(executed_docstring_path):
assert_that(executed_docstring_path.allure_report,
has_test_case("test_multiple_dynamic_labels",
has_feature("first feature"),
has_feature("second feature"),
has_epic("first epic"),
has_epic("second epic"),
has_story("first story"),
has_story("second story"),
)
)
14 changes: 14 additions & 0 deletions allure-pytest/test/integration/allure_ee/set_testcase_id_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ def test_set_testcase_id_label(executed_docstring_source):
has_label("as_id", 123),
)
)


def test_set_dynamic_testcase_id_label(executed_docstring_source):
"""
>>> import allure
>>> def test_allure_ee_id_dynamic_label_example():
... allure.dynamic.id(345)
"""
assert_that(executed_docstring_source.allure_report,
has_test_case("test_allure_ee_id_dynamic_label_example",
has_label("as_id", 345),
)
)
8 changes: 8 additions & 0 deletions allure-python-commons/src/_allure.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def label(label_type, *labels):
def severity(severity_level):
Dynamic.label(LabelType.SEVERITY, severity_level)

@staticmethod
def epic(*epics):
Dynamic.label(LabelType.EPIC, *epics)

@staticmethod
def feature(*features):
Dynamic.label(LabelType.FEATURE, *features)
Expand All @@ -120,6 +124,10 @@ def story(*stories):
def tag(*tags):
Dynamic.label(LabelType.TAG, *tags)

@staticmethod
def id(id):
Dynamic.label(LabelType.ID, id)

@staticmethod
def link(url, link_type=LinkType.LINK, name=None):
plugin_manager.hook.add_link(url=url, link_type=link_type, name=name)
Expand Down

0 comments on commit ef8d1f4

Please sign in to comment.