Skip to content

Commit 82a3d51

Browse files
Sup3rGeosseliverstov
authored andcommitted
handle steps outside tests/fixtures without breaking test (fixes #232 via #233)
1 parent ca105cb commit 82a3d51

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from . import init_step
2+
3+
init_step()
4+
5+
def test_pass_with_step_outside():
6+
"""
7+
>>> allure_report = getfixture('allure_report')
8+
>>> assert_that(allure_report,
9+
... has_test_case('test_pass_with_step_outside')
10+
... )
11+
"""
12+
assert True

allure-python-commons/src/reporter.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class AllureReporter(object):
1212
def __init__(self):
1313
self._items = OrderedDict()
14+
self._orphan_items = []
1415

1516
def _update_item(self, uuid, **kwargs):
1617
item = self._items[uuid] if uuid else self._items[next(reversed(self._items))]
@@ -74,12 +75,18 @@ def close_test(self, uuid):
7475

7576
def start_step(self, parent_uuid, uuid, step):
7677
parent_uuid = parent_uuid if parent_uuid else self._last_executable()
77-
self._items[parent_uuid].steps.append(step)
78-
self._items[uuid] = step
78+
if parent_uuid is None:
79+
self._orphan_items.append(uuid)
80+
else:
81+
self._items[parent_uuid].steps.append(step)
82+
self._items[uuid] = step
7983

8084
def stop_step(self, uuid, **kwargs):
81-
self._update_item(uuid, **kwargs)
82-
self._items.pop(uuid)
85+
if uuid in self._orphan_items:
86+
self._orphan_items.remove(uuid)
87+
else:
88+
self._update_item(uuid, **kwargs)
89+
self._items.pop(uuid)
8390

8491
def _attach(self, uuid, name=None, attachment_type=None, extension=None):
8592
mime_type = attachment_type

0 commit comments

Comments
 (0)