Skip to content

Commit 557d037

Browse files
committed
fix: mark parent step as failed if child step failed with soft check (#827)
1 parent 3cd731a commit 557d037

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

allure-pytest/src/listener.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from allure_pytest.utils import get_status, get_status_details
2424
from allure_pytest.utils import get_outcome_status, get_outcome_status_details
2525
from allure_pytest.utils import get_pytest_report_status
26+
from allure_pytest.utils import sync_steps_statuses
2627
from allure_pytest.utils import format_allure_link
2728
from allure_pytest.utils import get_history_id
2829
from allure_pytest.compat import getfixturedefs
@@ -226,6 +227,9 @@ def pytest_runtest_makereport(self, item, call):
226227
if test_result.status == Status.PASSED:
227228
test_result.status = status
228229
test_result.statusDetails = status_details
230+
has_failed_steps = sync_steps_statuses(test_result.steps)
231+
if has_failed_steps and not hasattr(report, "wasxfail"):
232+
test_result.status = Status.FAILED
229233

230234
if report.when == 'teardown':
231235
if status in (Status.FAILED, Status.BROKEN) and test_result.status == Status.PASSED:

allure-pytest/src/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ def get_pytest_report_status(pytest_report):
184184
return status
185185

186186

187+
def sync_steps_statuses(steps):
188+
any_failed = False
189+
for step in steps:
190+
if step.steps and sync_steps_statuses(step.steps):
191+
if step.status != Status.SKIPPED:
192+
step.status = Status.FAILED
193+
if step.status == Status.FAILED:
194+
any_failed = True
195+
return any_failed
196+
197+
187198
def get_history_id(full_name, parameters, original_values):
188199
return md5(
189200
full_name,

tests/allure_pytest/acceptance/status/base_step_status_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,49 @@ def test_pytest_fail_in_step(allure_pytest_runner: AllurePytestRunner):
7474
)
7575

7676

77+
def test_pytest_fail_in_nested_step_with_soft_check(allure_pytest_runner: AllurePytestRunner):
78+
"""
79+
>>> import allure
80+
>>> from pytest_check import check as soft_check
81+
82+
>>> def test_pytest_fail_in_nested_step_with_soft_check():
83+
... with allure.step("Parent step"):
84+
... with soft_check, allure.step("Child failed step"):
85+
... assert False
86+
... with soft_check, allure.step("Child passed step"):
87+
... assert True
88+
"""
89+
from pytest_check import check_log
90+
91+
allure_results = allure_pytest_runner.run_docstring()
92+
# Prevent failed soft check checks from triggering an 'assert False'.
93+
check_log.clear_failures()
94+
95+
assert_that(
96+
allure_results,
97+
has_test_case(
98+
"test_pytest_fail_in_nested_step_with_soft_check",
99+
with_status("failed"),
100+
has_step(
101+
"Parent step",
102+
with_status("failed"),
103+
has_step(
104+
"Child failed step",
105+
with_status("failed"),
106+
has_status_details(
107+
with_message_contains("AssertionError: assert False"),
108+
with_trace_contains("test_pytest_fail_in_nested_step_with_soft_check")
109+
)
110+
),
111+
has_step(
112+
"Child passed step",
113+
with_status("passed")
114+
)
115+
)
116+
)
117+
)
118+
119+
77120
def test_pytest_bytes_data_in_assert(allure_pytest_runner: AllurePytestRunner):
78121
"""
79122
>>> import allure

0 commit comments

Comments
 (0)