Skip to content

Commit 12085cd

Browse files
authored
Fix squashed results when using rerunfailures (fixes #735) (#736)
1 parent 690c6ea commit 12085cd

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

allure-pytest/src/listener.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ def pytest_runtest_makereport(self, item, call):
224224
if report.capstderr:
225225
self.attach_data(report.capstderr, "stderr", AttachmentType.TEXT, None)
226226

227+
@pytest.hookimpl(hookwrapper=True)
228+
def pytest_runtest_logfinish(self, nodeid, location):
229+
yield
230+
uuid = self._cache.pop(nodeid)
231+
if uuid:
232+
self.allure_logger.close_test(uuid)
233+
227234
@allure_commons.hookimpl
228235
def attach_data(self, body, name, attachment_type, extension):
229236
self.allure_logger.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension)

tests/allure_pytest/externals/pytest_rerunfailures/pytest_rerunfailures_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,30 @@ def test_pytest_rerunfailures_example(request):
4141
with_status(status)
4242
)
4343
)
44+
45+
46+
@allure.issue("735")
47+
@allure.feature("Integration")
48+
def test_separate_result_for_each_rerun(rerunfailures_runner: AllurePytestRunner):
49+
testfile_content = (
50+
"""
51+
import pytest
52+
53+
@pytest.mark.flaky(reruns=1)
54+
def test_pytest_rerunfailures_example(request):
55+
assert False
56+
"""
57+
)
58+
59+
def __count_labels(tc, name):
60+
return len(
61+
[label["value"] for label in tc["labels"] if label["name"] == name]
62+
)
63+
64+
output = rerunfailures_runner.run_pytest(testfile_content)
65+
66+
assert len(output.test_cases) == 2
67+
assert __count_labels(output.test_cases[0], "suite") == 1
68+
assert __count_labels(output.test_cases[0], "tag") == 1
69+
assert __count_labels(output.test_cases[1], "suite") == 1
70+
assert __count_labels(output.test_cases[1], "tag") == 1

0 commit comments

Comments
 (0)