Skip to content

Commit a9f22ef

Browse files
authored
Integrate pytest-rerunfailures (closes # 121 via #272)
1 parent 3324de4 commit a9f22ef

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

allure-pytest/src/listener.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,11 @@ def stop_fixture(self, parent_uuid, uuid, name, exc_type, exc_val, exc_tb):
5858
statusDetails=get_status_details(exc_type, exc_val, exc_tb))
5959

6060
@pytest.hookimpl(hookwrapper=True)
61-
def pytest_runtest_protocol(self, item):
61+
def pytest_runtest_setup(self, item):
6262
uuid = self._cache.set(item.nodeid)
6363
test_result = TestResult(name=item.name, uuid=uuid)
6464
self.allure_logger.schedule_test(uuid, test_result)
65-
yield
66-
uuid = self._cache.pop(item.nodeid)
67-
self.allure_logger.close_test(uuid)
6865

69-
@pytest.hookimpl(hookwrapper=True)
70-
def pytest_runtest_setup(self, item):
7166
yield
7267
uuid = self._cache.get(item.nodeid)
7368
test_result = self.allure_logger.get_test(uuid)
@@ -186,6 +181,9 @@ def pytest_runtest_makereport(self, item, call):
186181
test_result.status = status
187182
test_result.statusDetails = status_details
188183

184+
uuid = self._cache.pop(item.nodeid)
185+
self.allure_logger.close_test(uuid)
186+
189187
@allure_commons.hookimpl
190188
def attach_data(self, body, name, attachment_type, extension):
191189
self.allure_logger.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension)

allure-pytest/test/integrations/__init__.py

Whitespace-only changes.

allure-pytest/test/integrations/rerunfailures/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def pytest_ignore_collect(path, config):
3+
return config.pluginmanager.hasplugin('xdist')
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import threading
2+
import pytest
3+
4+
lord_of_the_flies = threading.local()
5+
6+
7+
@pytest.mark.flaky(reruns=5)
8+
def test_rerunfialures_failed_to_passed():
9+
"""
10+
>>> allure_report = getfixture('allure_report')
11+
12+
>>> assert_that(allure_report,
13+
... has_test_case('test_rerunfialures_failed_to_passed',
14+
... with_status('failed')
15+
... )
16+
... )
17+
18+
>>> assert_that(allure_report,
19+
... has_test_case('test_rerunfialures_failed_to_passed',
20+
... with_status('passed')
21+
... )
22+
... )
23+
"""
24+
saved = getattr(lord_of_the_flies, 'good', False)
25+
lord_of_the_flies.good = saved or 'maybe next time'
26+
assert saved

allure-pytest/tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ setenv = ALLURE_INDENT_OUTPUT=yep
1414

1515
deps =
1616
pyhamcrest
17+
pytest-rerunfailures
1718
{distshare}/allure-python-commons-2*.zip
1819
{distshare}/allure-python-commons-test-2*.zip
1920

0 commit comments

Comments
 (0)