Skip to content

Commit 138ff49

Browse files
committed
Change in core Thread to Process
Now step correct showing in Thread
1 parent 27bf63c commit 138ff49

File tree

9 files changed

+55
-18
lines changed

9 files changed

+55
-18
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
*.egg-info
99

1010
*/build
11-
*/dist
11+
*/dist
12+
.eggs

allure-pytest/src/listener.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from allure_commons.utils import uuid4
66
from allure_commons.utils import represent
77
from allure_commons.utils import platform_label
8-
from allure_commons.utils import host_tag, thread_tag
8+
from allure_commons.utils import host_tag, thread_tag, thread_tag_detail
99
from allure_commons.reporter import AllureReporter
1010
from allure_commons.model2 import TestStepResult, TestResult, TestBeforeResult, TestAfterResult
1111
from allure_commons.model2 import TestResultContainer
@@ -36,7 +36,7 @@ def __init__(self, config):
3636
@allure_commons.hookimpl
3737
def start_step(self, uuid, title, params):
3838
parameters = [Parameter(name=name, value=value) for name, value in params.items()]
39-
step = TestStepResult(name=title, start=now(), parameters=parameters)
39+
step = TestStepResult(name=title, start=now(), parameters=parameters, thrd=thread_tag_detail())
4040
self.allure_logger.start_step(None, uuid, step)
4141

4242
@allure_commons.hookimpl
@@ -48,7 +48,7 @@ def stop_step(self, uuid, exc_type, exc_val, exc_tb):
4848

4949
@allure_commons.hookimpl
5050
def start_fixture(self, parent_uuid, uuid, name):
51-
after_fixture = TestAfterResult(name=name, start=now())
51+
after_fixture = TestAfterResult(name=name, start=now(), thrd=thread_tag_detail())
5252
self.allure_logger.start_after_fixture(parent_uuid, uuid, after_fixture)
5353

5454
@allure_commons.hookimpl
@@ -61,15 +61,15 @@ def stop_fixture(self, parent_uuid, uuid, name, exc_type, exc_val, exc_tb):
6161
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
6262
def pytest_runtest_protocol(self, item, nextitem):
6363
uuid = self._cache.push(item.nodeid)
64-
test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now())
64+
test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now(), thrd=thread_tag_detail())
6565
self.allure_logger.schedule_test(uuid, test_result)
6666
yield
6767

6868
@pytest.hookimpl(hookwrapper=True)
6969
def pytest_runtest_setup(self, item):
7070
if not self._cache.get(item.nodeid):
7171
uuid = self._cache.push(item.nodeid)
72-
test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now())
72+
test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now(), thrd=thread_tag_detail())
7373
self.allure_logger.schedule_test(uuid, test_result)
7474

7575
yield
@@ -80,7 +80,7 @@ def pytest_runtest_setup(self, item):
8080
group_uuid = self._cache.get(fixturedef)
8181
if not group_uuid:
8282
group_uuid = self._cache.push(fixturedef)
83-
group = TestResultContainer(uuid=group_uuid)
83+
group = TestResultContainer(uuid=group_uuid, thrd=thread_tag_detail())
8484
self.allure_logger.start_group(group_uuid, group)
8585
self.allure_logger.update_group(group_uuid, children=uuid)
8686
params = item.callspec.params if hasattr(item, 'callspec') else {}
@@ -128,13 +128,13 @@ def pytest_fixture_setup(self, fixturedef, request):
128128

129129
if not container_uuid:
130130
container_uuid = self._cache.push(fixturedef)
131-
container = TestResultContainer(uuid=container_uuid)
131+
container = TestResultContainer(uuid=container_uuid, thrd=thread_tag_detail())
132132
self.allure_logger.start_group(container_uuid, container)
133133

134134
self.allure_logger.update_group(container_uuid, start=now())
135135

136136
before_fixture_uuid = uuid4()
137-
before_fixture = TestBeforeResult(name=fixture_name, start=now())
137+
before_fixture = TestBeforeResult(name=fixture_name, start=now(), thrd=thread_tag_detail())
138138
self.allure_logger.start_before_fixture(container_uuid, before_fixture_uuid, before_fixture)
139139

140140
outcome = yield

allure-python-commons/src/_allure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from functools import wraps
22
from typing import Any, Callable, TypeVar
3+
import threading
34

45
from allure_commons._core import plugin_manager
56
from allure_commons.types import LabelType, LinkType

allure-python-commons/src/_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import threading
1+
import multiprocessing
22
from six import with_metaclass
33
from pluggy import PluginManager
44
from allure_commons import _hooks
55

66

77
class MetaPluginManager(type):
8-
_storage = threading.local()
8+
_storage = multiprocessing.Process
99

1010
@staticmethod
1111
def get_plugin_manager():

allure-python-commons/src/lifecycle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from allure_commons.utils import uuid4
1212
from allure_commons.utils import now
1313
from allure_commons.types import AttachmentType
14+
import threading
1415

1516

1617
class AllureLifecycle(object):
@@ -52,7 +53,7 @@ def write_test_case(self, uuid=None):
5253
@contextmanager
5354
def start_step(self, parent_uuid=None, uuid=None):
5455
parent = self._get_item(uuid=parent_uuid, item_type=ExecutableItem)
55-
step = TestStepResult()
56+
step = TestStepResult(thrd=threading.current_thread().name)
5657
step.start = now()
5758
parent.steps.append(step)
5859
self._items[uuid or uuid4()] = step

allure-python-commons/src/logger.py

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

1414

15+
def delete_step_thrd(data):
16+
if isinstance(data, list):
17+
for field in data:
18+
field = delete_step_thrd(field)
19+
elif isinstance(data, dict):
20+
for field in data.keys():
21+
if field == 'thrd':
22+
data.pop('thrd')
23+
break
24+
field = delete_step_thrd(data[field])
25+
return data
26+
1527
class AllureFileLogger(object):
1628

1729
def __init__(self, report_dir, clean=False):
@@ -32,6 +44,8 @@ def _report_item(self, item):
3244
indent = INDENT if os.environ.get("ALLURE_INDENT_OUTPUT") else None
3345
filename = item.file_pattern.format(prefix=uuid.uuid4())
3446
data = asdict(item, filter=lambda attr, value: not (type(value) != bool and not bool(value)))
47+
data = delete_step_thrd(data)
48+
3549
with io.open(os.path.join(self._report_dir, filename), 'w', encoding='utf8') as json_file:
3650
if sys.version_info.major < 3:
3751
json_file.write(

allure-python-commons/src/model2.py

Lines changed: 3 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"
@@ -22,6 +23,7 @@ class TestResultContainer(object):
2223
links = attrib(default=Factory(list))
2324
start = attrib(default=None)
2425
stop = attrib(default=None)
26+
thrd = attrib(default=None)
2527

2628

2729
@attrs
@@ -37,6 +39,7 @@ class ExecutableItem(object):
3739
parameters = attrib(default=Factory(list))
3840
start = attrib(default=None)
3941
stop = attrib(default=None)
42+
thrd = attrib(default=None)
4043

4144

4245
@attrs

allure-python-commons/src/reporter.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from collections import OrderedDict
22

3-
from allure_commons.types import AttachmentType
4-
from allure_commons.model2 import ExecutableItem
5-
from allure_commons.model2 import TestResult
6-
from allure_commons.model2 import Attachment, ATTACHMENT_PATTERN
7-
from allure_commons.utils import now
83
from allure_commons._core import plugin_manager
4+
from allure_commons.model2 import (ATTACHMENT_PATTERN, Attachment,
5+
ExecutableItem, TestResult)
6+
from allure_commons.types import AttachmentType
7+
from allure_commons.utils import now, thread_tag_detail
98

109

1110
class AllureReporter(object):
1211
def __init__(self):
1312
self._items = OrderedDict()
1413
self._orphan_items = []
14+
self._thread = thread_tag_detail()
1515

1616
def _update_item(self, uuid, **kwargs):
1717
item = self._items[uuid] if uuid else self._items[next(reversed(self._items))]
@@ -23,7 +23,21 @@ def _update_item(self, uuid, **kwargs):
2323
setattr(item, name, value)
2424

2525
def _last_executable(self):
26-
for _uuid in reversed(self._items):
26+
copy_items = self._items.copy()
27+
for _uuid in reversed(copy_items):
28+
if (
29+
hasattr(self._items[_uuid], "thrd")
30+
and self._items[_uuid].thrd != thread_tag_detail()
31+
):
32+
continue
33+
if isinstance(self._items[_uuid], ExecutableItem):
34+
return _uuid
35+
for _uuid in reversed(copy_items):
36+
if hasattr(self._items[_uuid], "thrd") and self._items[_uuid].thrd != self._thread:
37+
continue
38+
if isinstance(self._items[_uuid], ExecutableItem):
39+
return _uuid
40+
for _uuid in reversed(copy_items):
2741
if isinstance(self._items[_uuid], ExecutableItem):
2842
return _uuid
2943

allure-python-commons/src/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def thread_tag():
9696
return '{0}-{1}'.format(os.getpid(), threading.current_thread().name)
9797

9898

99+
def thread_tag_detail():
100+
return '{0}-{1}'.format(threading.get_native_id(), threading.current_thread().name)
101+
99102
def host_tag():
100103
return socket.gethostname()
101104

0 commit comments

Comments
 (0)