Skip to content

Commit 16bec18

Browse files
committed
Fixes
1 parent 1313905 commit 16bec18

File tree

6 files changed

+45
-34
lines changed

6 files changed

+45
-34
lines changed

reportportal_client/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
from .service import ReportPortalService
1818
from .steps import step
19+
from ._local import current
1920

2021
__all__ = [
2122
'ReportPortalService',
22-
'step'
23+
'step',
24+
'current'
2325
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2022 https://reportportal.io .
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License
13+
from threading import local
14+
15+
16+
__INSTANCES = local()
17+
18+
19+
def current():
20+
return __INSTANCES.current
21+
22+
23+
def set_current(client):
24+
__INSTANCES.current = client

reportportal_client/client.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
limitations under the License.
1616
"""
1717
import logging
18-
from threading import local
18+
1919

2020
import requests
2121
from requests.adapters import HTTPAdapter
@@ -31,20 +31,11 @@
3131
from .helpers import uri_join, verify_value_length
3232
from .static.defines import NOT_FOUND
3333
from .steps import StepReporter
34+
from ._local import set_current
3435

3536
logger = logging.getLogger(__name__)
3637
logger.addHandler(logging.NullHandler())
3738

38-
__INSTANCES = local()
39-
40-
41-
def current():
42-
return __INSTANCES.current
43-
44-
45-
def _set_current(client):
46-
__INSTANCES.current = client
47-
4839

4940
class RPClient(object):
5041
"""Report portal client.
@@ -81,7 +72,7 @@ def __init__(self,
8172
:param max_pool_size: Option to set the maximum number of
8273
connections to save the pool.
8374
"""
84-
_set_current(self)
75+
set_current(self)
8576
self._batch_logs = []
8677
self.api_v1, self.api_v2 = 'v1', 'v2'
8778
self.endpoint = endpoint

reportportal_client/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ def get_function_params(func, args, kwargs):
171171
# Python 3.10.2
172172
# noinspection PyDeprecation
173173
arg_spec = inspect.getargspec(func)
174-
result = set()
174+
result = dict()
175175
for i, arg_name in enumerate(arg_spec.args):
176176
if arg_name in kwargs:
177177
break
178-
result.add((arg_name, str(args[i])))
178+
result[arg_name] = str(args[i])
179179
for arg_name, arg_value in kwargs.items():
180-
result.add((str(arg_name), str(arg_value)))
180+
result[arg_name] = str(arg_value)
181181
return result
182182

183183

reportportal_client/helpers.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from .errors import EntryCreatedError as EntryCreatedError, \
33
ResponseError as ResponseError
44
from logging import Logger
55

6-
from typing import Text, Tuple, Set, Callable, Any, Dict, Optional
6+
from typing import Text, Tuple, List, Callable, Any, Dict, Optional
77
from requests import Response
88

99
logger: Logger
@@ -23,6 +23,6 @@ def get_error_messages(data: dict) -> list: ...
2323
def verify_value_length(attributes: list[dict]) -> list[dict]: ...
2424
def timestamp() -> Text: ...
2525
def get_function_params(func: Callable, args: Tuple[Any, ...],
26-
kwargs: Dict[Text, Any]) -> Set[Tuple[Text, Text]]: ...
26+
kwargs: Dict[Text, Any]) -> Dict[Text, Text]: ...
2727
def evaluate_status(current_status:Optional[Text],
2828
child_status:Optional[Text]) -> Text: ...

reportportal_client/steps/__init__.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313
import logging
1414
from functools import wraps
1515

16-
from reportportal_client import client
16+
from reportportal_client._local import current
1717
from reportportal_client.helpers import get_function_params, evaluate_status, \
1818
timestamp
1919
from reportportal_client.static.defines import ItemStartType, NOT_FOUND
2020

21-
NESTED_STEP_ITEMS = (ItemStartType.STEP, ItemStartType.SCENARIO,
22-
ItemStartType.BEFORE_CLASS, ItemStartType.BEFORE_GROUPS,
23-
ItemStartType.BEFORE_METHOD, ItemStartType.BEFORE_SUITE,
24-
ItemStartType.BEFORE_TEST, ItemStartType.AFTER_TEST,
25-
ItemStartType.AFTER_SUITE, ItemStartType.AFTER_CLASS,
26-
ItemStartType.AFTER_GROUPS, ItemStartType.AFTER_METHOD)
21+
NESTED_STEP_ITEMS = ('step', 'scenario', 'before_class', 'before_groups',
22+
'before_method', 'before_suite', 'before_test',
23+
'after_test', 'after_suite', 'after_class',
24+
'after_groups', 'after_method')
2725

2826
logger = logging.getLogger(__name__)
2927
logger.addHandler(logging.NullHandler())
@@ -37,20 +35,16 @@ def __init__(self, rp_client):
3735

3836
def set_parent(self, item_type, parent_id):
3937
if parent_id is not NOT_FOUND:
40-
if str(item_type).upper() in NESTED_STEP_ITEMS:
38+
if item_type.lower() in NESTED_STEP_ITEMS:
4139
self.__levels.append(parent_id)
4240

4341
def get_parent(self):
4442
if len(self.__levels) > 0:
4543
return self.__levels[-1]
4644

4745
def remove_parent(self, parent_id=None):
48-
if parent_id is NOT_FOUND:
49-
return
50-
if parent_id is not None:
51-
if self.__levels[-1] != parent_id:
52-
return
53-
return self.__levels.pop()
46+
if len(self.__levels) > 0 and self.__levels[-1] == parent_id:
47+
return self.__levels.pop()
5448

5549
def start_nested_step(self,
5650
name,
@@ -60,7 +54,7 @@ def start_nested_step(self,
6054
parent_id = self.get_parent()
6155
if parent_id is None:
6256
return
63-
self.client.start_test_item(name, start_time, ItemStartType.STEP,
57+
self.client.start_test_item(name, start_time, 'step',
6458
has_stats=False,
6559
parameters=parameters,
6660
parent_item_id=parent_id)
@@ -80,7 +74,7 @@ def __init__(self, name, params, status, rp_client):
8074
self.name = name
8175
self.params = params
8276
self.status = status
83-
self.client = rp_client if rp_client is not None else client.current()
77+
self.client = rp_client if rp_client is not None else current()
8478

8579
def __enter__(self):
8680
self.client.step_reporter \

0 commit comments

Comments
 (0)