Skip to content

Commit 7f4f322

Browse files
committed
Fixes
1 parent c4951f8 commit 7f4f322

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

reportportal_client/_local/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818

1919
def current():
20-
return __INSTANCES.current
20+
if hasattr(__INSTANCES, 'current'):
21+
return __INSTANCES.current
2122

2223

2324
def set_current(client):

reportportal_client/steps/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,19 @@ def __init__(self, name, params, status, rp_client):
7474
self.name = name
7575
self.params = params
7676
self.status = status
77-
self.client = rp_client if rp_client is not None else current()
77+
self.client = rp_client if rp_client else current()
7878
self.__item_id = None
7979

8080
def __enter__(self):
81+
if not self.client:
82+
return
8183
self.__item_id = self.client.step_reporter \
8284
.start_nested_step(self.name, timestamp(), parameters=self.params)
8385
logger.info("Parameters: " + str(self.params))
8486

8587
def __exit__(self, exc_type, exc_val, exc_tb):
88+
if not self.__item_id:
89+
return
8690
step_status = self.status
8791
if any((exc_type, exc_val, exc_tb)):
8892
step_status = 'FAILED'
@@ -102,11 +106,8 @@ def wrapper(*args, **kwargs):
102106
return wrapper
103107

104108

105-
def step(func_or_name, name=None, params=None, status='PASSED',
106-
rp_client=None):
107-
if callable(func_or_name):
108-
if name is None:
109-
name = func_or_name.__name__
110-
return Step(name, params, status, rp_client)(func_or_name)
111-
else:
112-
return Step(func_or_name, params, status, rp_client)
109+
def step(name_source, params=None, status='PASSED', rp_client=None):
110+
if callable(name_source):
111+
name = name_source.__name__
112+
return Step(name, params, status, rp_client)(name_source)
113+
return Step(str(name_source), params, status, rp_client)

reportportal_client/steps/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Step:
4646
params: Dict = ...
4747
status: Text = ...
4848
client: RPClient = ...
49+
__item_id: Optional[Text] = ...
4950

5051
def __init__(self,
5152
name: Text,
@@ -60,8 +61,7 @@ class Step:
6061
def __call__(self, func: Callable) -> Callable: ...
6162

6263

63-
def step(func_or_name: Union[Callable, Text],
64-
name: Text = ...,
64+
def step(name_source: Union[Callable, Text],
6565
params: Dict = ...,
6666
status: Text = ...,
67-
rp_client: RPClient = ...) -> None: ...
67+
rp_client: RPClient = ...) -> Step: ...

tests/steps/test_steps.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,23 @@ def test_nested_steps_reported_with_parent(rp_client):
3131
print("Hello nested steps")
3232
assert rp_client.session.post.call_count == 1
3333
assert rp_client.session.put.call_count == 1
34+
35+
36+
def test_nested_step_name(rp_client):
37+
rp_client.step_reporter.set_parent('STEP', PARENT_STEP_ID)
38+
39+
with step(NESTED_STEP_NAME, rp_client=rp_client):
40+
print("Hello nested steps")
41+
42+
assert rp_client.session.post.call_args[1]['json']['name'] == \
43+
NESTED_STEP_NAME
44+
45+
46+
def test_nested_step_times(rp_client):
47+
rp_client.step_reporter.set_parent('STEP', PARENT_STEP_ID)
48+
49+
with step(NESTED_STEP_NAME, rp_client=rp_client):
50+
print("Hello nested steps")
51+
52+
assert rp_client.session.post.call_args[1]['json']['startTime']
53+
assert rp_client.session.put.call_args[1]['json']['endTime']

0 commit comments

Comments
 (0)