Skip to content

Commit 014fda4

Browse files
committed
check fixtures children after any phases
1 parent bea7854 commit 014fda4

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

allure-pytest/src/listener.py

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

61+
def _update_fixtures_children(self, item):
62+
uuid = self._cache.get(item.nodeid)
63+
for fixturedef in _test_fixtures(item):
64+
group_uuid = self._cache.get(fixturedef)
65+
if group_uuid:
66+
group = self.allure_logger.get_item(group_uuid)
67+
else:
68+
group_uuid = self._cache.push(fixturedef)
69+
group = TestResultContainer(uuid=group_uuid)
70+
self.allure_logger.start_group(group_uuid, group)
71+
if uuid not in group.children:
72+
self.allure_logger.update_group(group_uuid, children=uuid)
73+
6174
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
6275
def pytest_runtest_protocol(self, item, nextitem):
6376
uuid = self._cache.push(item.nodeid)
@@ -71,20 +84,11 @@ def pytest_runtest_setup(self, item):
7184
uuid = self._cache.push(item.nodeid)
7285
test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now())
7386
self.allure_logger.schedule_test(uuid, test_result)
74-
7587
yield
76-
88+
self._update_fixtures_children(item)
7789
uuid = self._cache.get(item.nodeid)
7890
test_result = self.allure_logger.get_test(uuid)
79-
for fixturedef in _test_fixtures(item):
80-
group_uuid = self._cache.get(fixturedef)
81-
if not group_uuid:
82-
group_uuid = self._cache.push(fixturedef)
83-
group = TestResultContainer(uuid=group_uuid)
84-
self.allure_logger.start_group(group_uuid, group)
85-
self.allure_logger.update_group(group_uuid, children=uuid)
8691
params = item.callspec.params if hasattr(item, 'callspec') else {}
87-
8892
test_result.name = allure_name(item, params)
8993
full_name = allure_full_name(item)
9094
test_result.fullName = full_name
@@ -104,12 +108,14 @@ def pytest_runtest_call(self, item):
104108
self.allure_logger.schedule_test(uuid, test_result)
105109
test_result.start = now()
106110
yield
111+
self._update_fixtures_children(item)
107112
if test_result:
108113
test_result.stop = now()
109114

110115
@pytest.hookimpl(hookwrapper=True)
111116
def pytest_runtest_teardown(self, item):
112117
yield
118+
self._update_fixtures_children(item)
113119
uuid = self._cache.get(item.nodeid)
114120
test_result = self.allure_logger.get_test(uuid)
115121
test_result.labels.extend([Label(name=name, value=value) for name, value in allure_labels(item)])
@@ -132,7 +138,6 @@ def pytest_fixture_setup(self, fixturedef, request):
132138
container_uuid = self._cache.push(fixturedef)
133139
container = TestResultContainer(uuid=container_uuid)
134140
self.allure_logger.start_group(container_uuid, container)
135-
self.allure_logger.update_group(container_uuid, children=self._cache.get(request._pyfuncitem.nodeid))
136141

137142
self.allure_logger.update_group(container_uuid, start=now())
138143

0 commit comments

Comments
 (0)