Skip to content

Commit

Permalink
Fix squashed results when using rerunfailures (fixes #735) (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
delatrie committed Mar 14, 2023
1 parent 690c6ea commit 12085cd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions allure-pytest/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ def pytest_runtest_makereport(self, item, call):
if report.capstderr:
self.attach_data(report.capstderr, "stderr", AttachmentType.TEXT, None)

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logfinish(self, nodeid, location):
yield
uuid = self._cache.pop(nodeid)
if uuid:
self.allure_logger.close_test(uuid)

@allure_commons.hookimpl
def attach_data(self, body, name, attachment_type, extension):
self.allure_logger.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,30 @@ def test_pytest_rerunfailures_example(request):
with_status(status)
)
)


@allure.issue("735")
@allure.feature("Integration")
def test_separate_result_for_each_rerun(rerunfailures_runner: AllurePytestRunner):
testfile_content = (
"""
import pytest
@pytest.mark.flaky(reruns=1)
def test_pytest_rerunfailures_example(request):
assert False
"""
)

def __count_labels(tc, name):
return len(
[label["value"] for label in tc["labels"] if label["name"] == name]
)

output = rerunfailures_runner.run_pytest(testfile_content)

assert len(output.test_cases) == 2
assert __count_labels(output.test_cases[0], "suite") == 1
assert __count_labels(output.test_cases[0], "tag") == 1
assert __count_labels(output.test_cases[1], "suite") == 1
assert __count_labels(output.test_cases[1], "tag") == 1

0 comments on commit 12085cd

Please sign in to comment.