From 1e07a5f0199860e8fca3a01a2e3a922947e6fb03 Mon Sep 17 00:00:00 2001 From: liuyaohui666 <272236390@qq.com> Date: Fri, 21 Aug 2026 20:35:52 +0800 Subject: [PATCH] Fix excluded Behave steps leaking into results --- allure-behave/src/listener.py | 1 + .../behave_cmd/behave_cmd_test.py | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/allure-behave/src/listener.py b/allure-behave/src/listener.py index ad543526..fafdec9f 100644 --- a/allure-behave/src/listener.py +++ b/allure-behave/src/listener.py @@ -108,6 +108,7 @@ def stop_scenario(self, scenario): should_drop_excluded = self.hide_excluded and (scenario.skip_reason == TEST_PLAN_SKIP_REASON or not should_run) if should_drop_skipped_by_option or should_drop_excluded: + self.steps.clear() self.logger.drop_test(self.current_scenario_uuid) else: status = scenario_status(scenario) diff --git a/tests/allure_behave/acceptance/behave_support/behave_cmd/behave_cmd_test.py b/tests/allure_behave/acceptance/behave_support/behave_cmd/behave_cmd_test.py index 6e3fe849..65a123c3 100644 --- a/tests/allure_behave/acceptance/behave_support/behave_cmd/behave_cmd_test.py +++ b/tests/allure_behave/acceptance/behave_support/behave_cmd/behave_cmd_test.py @@ -1,7 +1,7 @@ from hamcrest import assert_that, all_of, not_ 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_title, with_status, with_steps def test_behave_tags_filter(docstring: str, behave_runner: AllureBehaveRunner): @@ -62,3 +62,41 @@ def test_behave_no_skipped_support(docstring: str, behave_runner: AllureBehaveRu ) ) ) + + +def test_hidden_tag_excluded_scenario_steps_are_not_reported( + docstring: str, + behave_runner: AllureBehaveRunner +): + """Feature: Behave hidden tag-excluded scenario support + + Scenario: Scenario without tag + Given an excluded step + + @tag + Scenario: Scenario with tag + Given an included step + """ + behave_runner.run_behave( + feature_literals=[docstring], + step_literals=[ + "given('an excluded step')(lambda c:None)\n" + "given('an included step')(lambda c:None)" + ], + options=["--tags=tag", "-D", "AllureFormatter.hide_excluded=True"] + ) + assert_that( + behave_runner.allure_results, + all_of( + not_( + has_test_case("Scenario without tag") + ), + has_test_case( + "Scenario with tag", + with_status("passed"), + with_steps( + has_title("Given an included step") + ) + ) + ) + )