Skip to content

Commit ec5c9e8

Browse files
author
Glazov Nikolay
committed
Add support for step in threading
1 parent 27bf63c commit ec5c9e8

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

allure-pytest/src/listener.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from allure_pytest.utils import get_outcome_status, get_outcome_status_details
2323
from allure_pytest.utils import get_pytest_report_status
2424
from allure_commons.utils import md5
25+
import threading
2526

2627

2728
class AllureListener(object):
@@ -36,8 +37,13 @@ def __init__(self, config):
3637
@allure_commons.hookimpl
3738
def start_step(self, uuid, title, params):
3839
parameters = [Parameter(name=name, value=value) for name, value in params.items()]
39-
step = TestStepResult(name=title, start=now(), parameters=parameters)
40-
self.allure_logger.start_step(None, uuid, step)
40+
step = TestStepResult(name=title, start=now(), parameters=parameters, thrd=threading.current_thread().name)
41+
if thread_tag() != self._thread:
42+
self.allure_logger.start_step(self.allure_logger.last_with_thread(), uuid, step)
43+
else:
44+
self.allure_logger.start_step(None, uuid, step)
45+
# step = TestStepResult(name=title, start=now(), parameters=parameters)
46+
# self.allure_logger.start_step(None, uuid, step)
4147

4248
@allure_commons.hookimpl
4349
def stop_step(self, uuid, exc_type, exc_val, exc_tb):
@@ -241,6 +247,12 @@ def add_description_html(self, test_description_html):
241247
if test_result:
242248
test_result.descriptionHtml = test_description_html
243249

250+
@allure_commons.hookimpl
251+
def add_thrd(self, test_description_html):
252+
test_result = self.allure_logger.get_test(None)
253+
if test_result:
254+
test_result.descriptionHtml = test_description_html
255+
244256
@allure_commons.hookimpl
245257
def add_link(self, url, link_type, name):
246258
test_result = self.allure_logger.get_test(None)

allure-python-commons/src/_core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import threading
2+
import multiprocessing
23
from six import with_metaclass
34
from pluggy import PluginManager
45
from allure_commons import _hooks
56

67

78
class MetaPluginManager(type):
89
_storage = threading.local()
10+
_storage = multiprocessing.Process
911

1012
@staticmethod
1113
def get_plugin_manager():

allure-python-commons/src/logger.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
INDENT = 4
1313

1414

15+
def delete_step_thrd(data):
16+
if "steps" in data.keys():
17+
for step in data['steps']:
18+
step.pop("thrd", None)
19+
step = delete_step_thrd(step)
20+
return data
21+
22+
1523
class AllureFileLogger(object):
1624

1725
def __init__(self, report_dir, clean=False):
@@ -32,6 +40,8 @@ def _report_item(self, item):
3240
indent = INDENT if os.environ.get("ALLURE_INDENT_OUTPUT") else None
3341
filename = item.file_pattern.format(prefix=uuid.uuid4())
3442
data = asdict(item, filter=lambda attr, value: not (type(value) != bool and not bool(value)))
43+
data = delete_step_thrd(data)
44+
3545
with io.open(os.path.join(self._report_dir, filename), 'w', encoding='utf8') as json_file:
3646
if sys.version_info.major < 3:
3747
json_file.write(

allure-python-commons/src/model2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from attr import attrs, attrib
22
from attr import Factory
3+
import threading
34

45

56
TEST_GROUP_PATTERN = "{prefix}-container.json"
@@ -37,6 +38,7 @@ class ExecutableItem(object):
3738
parameters = attrib(default=Factory(list))
3839
start = attrib(default=None)
3940
stop = attrib(default=None)
41+
thrd = attrib(default=None)
4042

4143

4244
@attrs

allure-python-commons/src/reporter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from collections import OrderedDict
2+
import os
3+
import shutil
24

35
from allure_commons.types import AttachmentType
46
from allure_commons.model2 import ExecutableItem
@@ -27,6 +29,13 @@ def _last_executable(self):
2729
if isinstance(self._items[_uuid], ExecutableItem):
2830
return _uuid
2931

32+
def last_with_thread(self):
33+
for _uuid in reversed(self._items):
34+
if self._items[_uuid].thrd != "MainThread":
35+
continue
36+
if isinstance(self._items[_uuid], ExecutableItem):
37+
return _uuid
38+
3039
def get_item(self, uuid):
3140
return self._items.get(uuid)
3241

@@ -111,6 +120,8 @@ def _attach(self, uuid, name=None, attachment_type=None, extension=None):
111120
def attach_file(self, uuid, source, name=None, attachment_type=None, extension=None):
112121
file_name = self._attach(uuid, name=name, attachment_type=attachment_type, extension=extension)
113122
plugin_manager.hook.report_attached_file(source=source, file_name=file_name)
123+
destination = os.path.join('./allure-results', file_name)
124+
shutil.copy2(source, destination)
114125

115126
def attach_data(self, uuid, body, name=None, attachment_type=None, extension=None):
116127
file_name = self._attach(uuid, name=name, attachment_type=attachment_type, extension=extension)

0 commit comments

Comments
 (0)