Skip to content

Commit 89e7161

Browse files
authored
attach from parametrized test (fixes #101 via #133)
1 parent 24020ca commit 89e7161

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
>>> allure_report = getfixture('allure_report')
3+
>>> assert_that(allure_report,
4+
... all_of(
5+
... has_property('test_cases', has_length(9)),
6+
... has_property('test_groups', has_length(0)),
7+
... has_property('attachments', has_length(11))
8+
... )) # doctest: +SKIP
9+
"""
10+
11+
import allure
12+
import pytest
13+
14+
BODY = ['I Like to', 'Move It']
15+
16+
17+
@pytest.mark.parametrize('attachment', BODY)
18+
def test_attach_data_from_parametrized_test(attachment):
19+
"""
20+
>>> allure_report = getfixture('allure_report')
21+
>>> for body in BODY:
22+
... assert_that(allure_report,
23+
... has_test_case('test_attach_data_from_parametrized_test[{body}]'.format(body=body),
24+
... has_attachment()
25+
... )
26+
... )
27+
"""
28+
allure.attach(attachment)

allure-python-commons/src/reporter.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def _update_item(self, uuid, **kwargs):
2020
else:
2121
setattr(item, name, value)
2222

23+
def _last_executable(self):
24+
for _uuid in reversed(self._items):
25+
if isinstance(self._items[_uuid], ExecutableItem):
26+
return _uuid
27+
2328
def get_item(self, uuid):
2429
return self._items.get(uuid)
2530

@@ -62,11 +67,7 @@ def close_test(self, uuid):
6267
plugin_manager.hook.report_result(result=test_case)
6368

6469
def start_step(self, parent_uuid, uuid, step):
65-
if not parent_uuid:
66-
for _uuid in reversed(self._items):
67-
if isinstance(self._items[_uuid], ExecutableItem):
68-
parent_uuid = _uuid
69-
break
70+
parent_uuid = parent_uuid if parent_uuid else self._last_executable()
7071
self._items[parent_uuid].steps.append(step)
7172
self._items[uuid] = step
7273

@@ -84,7 +85,7 @@ def _attach(self, uuid, name=None, attachment_type=None, extension=None):
8485

8586
file_name = ATTACHMENT_PATTERN.format(prefix=uuid, ext=extension)
8687
attachment = Attachment(source=file_name, name=name, type=mime_type)
87-
last_uuid = next(reversed(self._items))
88+
last_uuid = self._last_executable()
8889
self._items[last_uuid].attachments.append(attachment)
8990

9091
return file_name

0 commit comments

Comments
 (0)