Skip to content

Commit 1762bdd

Browse files
committed
Pydocs add
1 parent e8b4816 commit 1762bdd

File tree

3 files changed

+95
-7
lines changed

3 files changed

+95
-7
lines changed

reportportal_client/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def get_function_params(func, args, kwargs):
166166
:param func: the function to get arg names
167167
:param args: function's arg values
168168
:param kwargs: function's kwargs
169-
:return: a set of tuples (name, value)
169+
:return: a dictionary of values
170170
"""
171171
# Use deprecated method for python 2.7 compatibility, it's still here for
172172
# Python 3.10.2, so it's completely redundant to show the warning

reportportal_client/steps/__init__.py

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,37 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License
13-
import logging
13+
"""Report portal Nested Step handling module.
14+
15+
The module for handling and reporting Report Portal Nested Steps inside python
16+
test frameworks. Import 'step' function to use it as decorator or together with
17+
'with' keyword to divide your tests on smaller steps.
18+
19+
Usage as decorator:
20+
.. highlight:: python
21+
.. code-block:: python
22+
23+
from reportportal_client import step
24+
25+
@step
26+
def my_nested_step():
27+
pass
28+
29+
def test_my_nested_step():
30+
my_nested_step()
31+
32+
33+
Usage with 'with' keyword:
34+
.. highlight:: python
35+
.. code-block:: python
36+
37+
from reportportal_client import step
38+
39+
def test_my_nested_step():
40+
with step('My nested step', status='INFO'):
41+
pass
42+
43+
"""
1444
from functools import wraps
1545

1646
from reportportal_client._local import current
@@ -22,26 +52,42 @@
2252
'after_test', 'after_suite', 'after_class',
2353
'after_groups', 'after_method')
2454

25-
logger = logging.getLogger(__name__)
26-
logger.addHandler(logging.NullHandler())
27-
2855

2956
# noinspection PyUnresolvedReferences
3057
class StepReporter:
58+
"""Nested Steps context handling class."""
59+
3160
def __init__(self, rp_client):
61+
"""Initialize required attributes.
62+
63+
:param rp_client: Report Portal client which will be used to report
64+
steps
65+
"""
3266
self.__levels = []
3367
self.client = rp_client
3468

3569
def set_parent(self, item_type, parent_id):
70+
"""Put an id into parent items queue if it has correct type.
71+
72+
:param item_type: type of the parent item
73+
:param parent_id: ID of the parent item
74+
"""
3675
if parent_id is not NOT_FOUND:
3776
if item_type.lower() in NESTED_STEP_ITEMS:
3877
self.__levels.append(parent_id)
3978

4079
def get_parent(self):
80+
"""Retrieve the last item in the parent queue."""
4181
if len(self.__levels) > 0:
4282
return self.__levels[-1]
4383

4484
def remove_parent(self, parent_id):
85+
"""Remove the last item in the parent queue.
86+
87+
Remove the last item in the parent queue if it's equal to the method's
88+
argument.
89+
:param parent_id: item ID to remove
90+
"""
4591
if len(self.__levels) > 0 and self.__levels[-1] == parent_id:
4692
return self.__levels.pop()
4793

@@ -50,6 +96,12 @@ def start_nested_step(self,
5096
start_time,
5197
parameters=None,
5298
**kwargs):
99+
"""Start Nested Step on Report Portal.
100+
101+
:param name: Nested Step name
102+
:param start_time: Nested Step start time
103+
:param parameters: Nested Step parameters
104+
"""
53105
parent_id = self.get_parent()
54106
if parent_id is None:
55107
return
@@ -63,20 +115,38 @@ def finish_nested_step(self,
63115
end_time,
64116
status=None,
65117
**kwargs):
118+
"""Finish a Nested Step on Report Portal.
119+
120+
:param item_id: Nested Step item ID
121+
:param end_time: Nested Step finish time
122+
:param status: Nested Step finish status
123+
"""
66124
if not self.remove_parent(item_id):
67125
return
68126
return self.client.finish_test_item(item_id, end_time, status=status)
69127

70128

71129
class Step:
130+
"""Step context handling class."""
131+
72132
def __init__(self, name, params, status, rp_client):
133+
"""Initialize required attributes.
134+
135+
:param name: Nested Step name
136+
:param params: Nested Step parameters
137+
:param status: Nested Step status which will be reported on
138+
successful step finish
139+
:param rp_client: Report Portal client which will be used to report
140+
the step
141+
"""
73142
self.name = name
74143
self.params = params
75144
self.status = status
76145
self.client = rp_client
77146
self.__item_id = None
78147

79148
def __enter__(self):
149+
"""Enter the runtime context related to this object."""
80150
# Cannot call _local.current() early since it will be initialized
81151
# before client put something in there
82152
rp_client = self.client if self.client else current()
@@ -94,6 +164,7 @@ def __enter__(self):
94164
item_id=self.__item_id)
95165

96166
def __exit__(self, exc_type, exc_val, exc_tb):
167+
"""Exit the runtime context related to this object."""
97168
# Cannot call _local.current() early since it will be initialized
98169
# before client put something in there
99170
rp_client = self.client if self.client else current()
@@ -109,6 +180,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
109180
.finish_nested_step(self.__item_id, timestamp(), step_status)
110181

111182
def __call__(self, func):
183+
"""The method is called when the instance is “called” as a function."""
184+
112185
@wraps(func)
113186
def wrapper(*args, **kwargs):
114187
__tracebackhide__ = True
@@ -122,6 +195,21 @@ def wrapper(*args, **kwargs):
122195

123196

124197
def step(name_source, params=None, status='PASSED', rp_client=None):
198+
"""Nested step report function.
199+
200+
Create a Nested Step inside a test method on Report Portal.
201+
:param name_source: a function or string which will be used as step's name
202+
:param params: nested step parameters which will be reported as the
203+
first step entry. If 'name_source' is a function
204+
reference and this parameter is not specified, they
205+
will be taken from the function.
206+
:param status: the status which will be reported after the step
207+
passed. Can be any of legal Report Portal statuses.
208+
E.G.: PASSED, WARN, INFO, etc. Default value is PASSED
209+
:param rp_client: overrides Report Portal client which will be used in
210+
step reporting
211+
:return: a step context object
212+
"""
125213
if callable(name_source):
126214
name = name_source.__name__
127215
return Step(name, params, status, rp_client)(name_source)

reportportal_client/steps/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ class Step:
4545
name: Text = ...
4646
params: Dict = ...
4747
status: Text = ...
48-
client: RPClient = ...
48+
client: Optional[RPClient] = ...
4949
__item_id: Optional[Text] = ...
5050

5151
def __init__(self,
5252
name: Text,
5353
params: Dict,
5454
status: Text,
55-
rp_client: RPClient) -> None: ...
55+
rp_client: Optional[RPClient]) -> None: ...
5656

5757
def __enter__(self) -> None: ...
5858

0 commit comments

Comments
 (0)