Skip to content

Commit 466b1dd

Browse files
authored
Set testCaseId for all test results produced by allure_behave (#883)
1 parent 5833093 commit 466b1dd

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

allure-behave/src/listener.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import allure_commons
33
from allure_commons.reporter import AllureReporter
44
from allure_commons.utils import uuid4
5+
from allure_commons.utils import md5
56
from allure_commons.utils import now
67
from allure_commons.utils import platform_label
78
from allure_commons.types import LabelType, AttachmentType, LinkType
@@ -80,6 +81,7 @@ def start_scenario(self, scenario):
8081
test_case.fullName = get_fullname(scenario)
8182
test_case.titlePath = get_title_path(scenario)
8283
test_case.historyId = scenario_history_id(scenario)
84+
test_case.testCaseId = md5(test_case.fullName)
8385
test_case.description = '\n'.join(scenario.description)
8486
test_case.parameters = scenario_parameters(scenario)
8587

allure-python-commons-test/src/result.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,9 @@ def has_history_id(matcher=None):
233233
return has_entry('historyId', matcher or anything())
234234

235235

236+
def has_test_case_id(matcher=None):
237+
return has_entry('testCaseId', matcher or anything())
238+
239+
236240
def has_full_name(matcher):
237241
return has_entry("fullName", matcher)

tests/allure_behave/acceptance/behave_support/scenarios/scenario_test.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import pytest
22
from hamcrest import assert_that
3+
from hamcrest import contains_string
4+
from hamcrest import all_of
35
from tests.allure_behave.behave_runner import AllureBehaveRunner
46
from allure_commons_test.report import has_test_case
57
from allure_commons_test.result import with_status
68
from allure_commons_test.result import has_step
9+
from allure_commons_test.result import has_full_name
10+
from allure_commons_test.result import has_test_case_id
11+
from allure_commons_test.result import has_history_id
712

813

914
@pytest.mark.parametrize(["step", "status"], [
@@ -140,3 +145,32 @@ def test_nameless_scenario(docstring, behave_runner: AllureBehaveRunner):
140145
with_status("passed")
141146
)
142147
)
148+
149+
150+
def test_identifiers_are_set(docstring, behave_runner: AllureBehaveRunner):
151+
"""
152+
Feature: Foo
153+
154+
Scenario: Bar:
155+
Given noop
156+
"""
157+
158+
behave_runner.run_behave(
159+
feature_literals=[docstring],
160+
step_literals=["given('noop')(lambda c:None)"]
161+
)
162+
163+
assert_that(
164+
behave_runner.allure_results,
165+
has_test_case(
166+
"Bar",
167+
has_full_name(
168+
all_of(
169+
contains_string("Foo"),
170+
contains_string("Bar"),
171+
),
172+
),
173+
has_test_case_id(),
174+
has_history_id(),
175+
),
176+
)

0 commit comments

Comments
 (0)