11
11
# See the License for the specific language governing permissions and
12
12
# limitations under the License
13
13
from reportportal_client import step
14
+ from reportportal_client ._local import set_current
14
15
15
16
NESTED_STEP_NAME = 'test nested step'
16
17
PARENT_STEP_ID = '123-123-1234-123'
17
18
NESTED_STEP_ID = '321-321-4321-321'
18
19
19
20
20
21
def test_nested_steps_are_skipped_without_parent (rp_client ):
21
- with step (NESTED_STEP_NAME , rp_client = rp_client ):
22
- print ("Hello nested steps" )
22
+ with step (NESTED_STEP_NAME ):
23
+ pass
24
+
23
25
assert rp_client .session .post .call_count == 0
24
26
assert rp_client .session .put .call_count == 0
25
27
26
28
27
29
def test_nested_steps_reported_with_parent (rp_client ):
28
30
rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
29
31
30
- with step (NESTED_STEP_NAME , rp_client = rp_client ):
31
- print ("Hello nested steps" )
32
+ with step (NESTED_STEP_NAME ):
33
+ pass
34
+
32
35
assert rp_client .session .post .call_count == 1
33
36
assert rp_client .session .put .call_count == 1
34
37
35
38
39
+ def test_nested_steps_are_skipped_without_client (rp_client ):
40
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
41
+ set_current (None )
42
+ with step (NESTED_STEP_NAME ):
43
+ pass
44
+
45
+ assert rp_client .session .post .call_count == 0
46
+ assert rp_client .session .put .call_count == 0
47
+
48
+
36
49
def test_nested_step_name (rp_client ):
37
50
rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
38
51
39
- with step (NESTED_STEP_NAME , rp_client = rp_client ):
40
- print ( "Hello nested steps" )
52
+ with step (NESTED_STEP_NAME ):
53
+ pass
41
54
42
55
assert rp_client .session .post .call_args [1 ]['json' ]['name' ] == \
43
56
NESTED_STEP_NAME
@@ -46,8 +59,93 @@ def test_nested_step_name(rp_client):
46
59
def test_nested_step_times (rp_client ):
47
60
rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
48
61
49
- with step (NESTED_STEP_NAME , rp_client = rp_client ):
50
- print ( "Hello nested steps" )
62
+ with step (NESTED_STEP_NAME ):
63
+ pass
51
64
52
65
assert rp_client .session .post .call_args [1 ]['json' ]['startTime' ]
53
66
assert rp_client .session .put .call_args [1 ]['json' ]['endTime' ]
67
+
68
+
69
+ @step
70
+ def nested_step ():
71
+ pass
72
+
73
+
74
+ def test_nested_step_decorator (rp_client ):
75
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
76
+ nested_step ()
77
+
78
+ assert rp_client .session .post .call_count == 1
79
+ assert rp_client .session .put .call_count == 1
80
+ assert len (rp_client ._log_manager ._logs_batch ) == 0
81
+
82
+
83
+ def test_nested_step_failed (rp_client ):
84
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
85
+ try :
86
+ with step (NESTED_STEP_NAME ):
87
+ raise AssertionError
88
+ except AssertionError :
89
+ pass
90
+ assert rp_client .session .post .call_count == 1
91
+ assert rp_client .session .put .call_count == 1
92
+ assert rp_client .session .put .call_args [1 ]['json' ]['status' ] == 'FAILED'
93
+
94
+
95
+ def test_nested_step_custom_status (rp_client ):
96
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
97
+ with step (NESTED_STEP_NAME , status = 'INFO' ):
98
+ pass
99
+ assert rp_client .session .post .call_count == 1
100
+ assert rp_client .session .put .call_count == 1
101
+ assert rp_client .session .put .call_args [1 ]['json' ]['status' ] == 'INFO'
102
+
103
+
104
+ def test_nested_step_custom_status_failed (rp_client ):
105
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
106
+ try :
107
+ with step (NESTED_STEP_NAME , status = 'INFO' ):
108
+ raise AssertionError
109
+ except AssertionError :
110
+ pass
111
+ assert rp_client .session .post .call_count == 1
112
+ assert rp_client .session .put .call_count == 1
113
+ assert rp_client .session .put .call_args [1 ]['json' ]['status' ] == 'FAILED'
114
+
115
+
116
+ @step
117
+ def nested_step_params (param1 , param2 , param3 = None ):
118
+ pass
119
+
120
+
121
+ def test_verify_parameters_logging_default_value (rp_client ):
122
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
123
+ nested_step_params (1 , 'two' )
124
+ assert len (rp_client ._log_manager ._logs_batch ) == 1
125
+ assert rp_client ._log_manager ._logs_batch [0 ].message \
126
+ == "Parameters: {'param1': 1, 'param2': 'two'}"
127
+
128
+
129
+ def test_verify_parameters_logging_no_default_value (rp_client ):
130
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
131
+ nested_step_params (1 , 'two' , 'three' )
132
+ assert len (rp_client ._log_manager ._logs_batch ) == 1
133
+ assert rp_client ._log_manager ._logs_batch [0 ].message \
134
+ == "Parameters: {'param1': 1, 'param2': 'two', 'param3': 'three'}"
135
+
136
+
137
+ def test_verify_parameters_logging_named_value (rp_client ):
138
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
139
+ nested_step_params (1 , 'two' , param3 = 'three' )
140
+ assert len (rp_client ._log_manager ._logs_batch ) == 1
141
+ assert rp_client ._log_manager ._logs_batch [0 ].message \
142
+ == "Parameters: {'param1': 1, 'param2': 'two', 'param3': 'three'}"
143
+
144
+
145
+ def test_verify_parameters_inline_logging (rp_client ):
146
+ rp_client .step_reporter .set_parent ('STEP' , PARENT_STEP_ID )
147
+ with step (NESTED_STEP_NAME , params = {'param1' : 1 , 'param2' : 'two' }):
148
+ pass
149
+ assert len (rp_client ._log_manager ._logs_batch ) == 1
150
+ assert rp_client ._log_manager ._logs_batch [0 ].message \
151
+ == "Parameters: {'param1': 1, 'param2': 'two'}"
0 commit comments