From f799a932f307bc2bd6f1d08a6fea84ef7969309c Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Fri, 28 Nov 2025 18:56:10 +0700 Subject: [PATCH] feat(behave): add testCaseId --- allure-behave/src/listener.py | 2 ++ allure-python-commons-test/src/result.py | 4 +++ .../behave_support/scenarios/scenario_test.py | 34 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/allure-behave/src/listener.py b/allure-behave/src/listener.py index 7d5d8753..e7f9be8a 100644 --- a/allure-behave/src/listener.py +++ b/allure-behave/src/listener.py @@ -2,6 +2,7 @@ import allure_commons from allure_commons.reporter import AllureReporter from allure_commons.utils import uuid4 +from allure_commons.utils import md5 from allure_commons.utils import now from allure_commons.utils import platform_label from allure_commons.types import LabelType, AttachmentType, LinkType @@ -80,6 +81,7 @@ def start_scenario(self, scenario): test_case.fullName = get_fullname(scenario) test_case.titlePath = get_title_path(scenario) test_case.historyId = scenario_history_id(scenario) + test_case.testCaseId = md5(test_case.fullName) test_case.description = '\n'.join(scenario.description) test_case.parameters = scenario_parameters(scenario) diff --git a/allure-python-commons-test/src/result.py b/allure-python-commons-test/src/result.py index 93a393cd..fb83000c 100644 --- a/allure-python-commons-test/src/result.py +++ b/allure-python-commons-test/src/result.py @@ -233,5 +233,9 @@ def has_history_id(matcher=None): return has_entry('historyId', matcher or anything()) +def has_test_case_id(matcher=None): + return has_entry('testCaseId', matcher or anything()) + + def has_full_name(matcher): return has_entry("fullName", matcher) diff --git a/tests/allure_behave/acceptance/behave_support/scenarios/scenario_test.py b/tests/allure_behave/acceptance/behave_support/scenarios/scenario_test.py index 28b3f696..bb2cbfb3 100644 --- a/tests/allure_behave/acceptance/behave_support/scenarios/scenario_test.py +++ b/tests/allure_behave/acceptance/behave_support/scenarios/scenario_test.py @@ -1,9 +1,14 @@ import pytest from hamcrest import assert_that +from hamcrest import contains_string +from hamcrest import all_of from tests.allure_behave.behave_runner import AllureBehaveRunner from allure_commons_test.report import has_test_case from allure_commons_test.result import with_status from allure_commons_test.result import has_step +from allure_commons_test.result import has_full_name +from allure_commons_test.result import has_test_case_id +from allure_commons_test.result import has_history_id @pytest.mark.parametrize(["step", "status"], [ @@ -140,3 +145,32 @@ def test_nameless_scenario(docstring, behave_runner: AllureBehaveRunner): with_status("passed") ) ) + + +def test_identifiers_are_set(docstring, behave_runner: AllureBehaveRunner): + """ + Feature: Foo + + Scenario: Bar: + Given noop + """ + + behave_runner.run_behave( + feature_literals=[docstring], + step_literals=["given('noop')(lambda c:None)"] + ) + + assert_that( + behave_runner.allure_results, + has_test_case( + "Bar", + has_full_name( + all_of( + contains_string("Foo"), + contains_string("Bar"), + ), + ), + has_test_case_id(), + has_history_id(), + ), + )