@@ -85,33 +85,28 @@ def test_request_is_ignored_because_no_action(
85
85
86
86
87
87
def test_execution_logging_for_successful_requests (
88
- caplog ,
88
+ capturelogs ,
89
89
webhook_create_example : BugzillaWebhookRequest ,
90
90
actions_example : Actions ,
91
91
mocked_bugzilla ,
92
92
):
93
93
mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
94
94
95
- with caplog .at_level (logging .DEBUG ):
95
+ with capturelogs . for_logger ( "jbi.runner" ) .at_level (logging .DEBUG ):
96
96
execute_action (
97
97
request = webhook_create_example ,
98
98
actions = actions_example ,
99
99
)
100
100
101
- captured_log_msgs = (
102
- r .msg % r .args for r in caplog .records if r .name == "jbi.runner"
103
- )
104
-
105
- for message in [
101
+ assert {
106
102
"Handling incoming request" ,
107
103
"Execute action 'devtest' for Bug 654321" ,
108
104
"Action 'devtest' executed successfully for Bug 654321" ,
109
- ]:
110
- assert message in captured_log_msgs
105
+ }.issubset (set (capturelogs .messages ))
111
106
112
107
113
108
def test_execution_logging_for_ignored_requests (
114
- caplog ,
109
+ capturelogs ,
115
110
webhook_create_example : BugzillaWebhookRequest ,
116
111
actions_example : Actions ,
117
112
mocked_bugzilla ,
@@ -120,41 +115,35 @@ def test_execution_logging_for_ignored_requests(
120
115
webhook_create_example .bug .whiteboard = "foo"
121
116
mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
122
117
123
- with caplog .at_level (logging .DEBUG ):
118
+ with capturelogs . for_logger ( "jbi.runner" ) .at_level (logging .DEBUG ):
124
119
with pytest .raises (IgnoreInvalidRequestError ):
125
120
execute_action (
126
121
request = webhook_create_example ,
127
122
actions = actions_example ,
128
123
)
129
124
130
- captured_log_msgs = [
131
- r .msg % r .args for r in caplog .records if r .name == "jbi.runner"
132
- ]
133
-
134
- assert captured_log_msgs == [
125
+ assert capturelogs .messages == [
135
126
"Handling incoming request" ,
136
127
"Ignore incoming request: no bug whiteboard matching action tags: devtest" ,
137
128
]
138
129
139
130
140
131
def test_action_is_logged_as_success_if_returns_true (
141
- caplog ,
132
+ capturelogs ,
142
133
webhook_create_example : BugzillaWebhookRequest ,
143
134
actions_example : Actions ,
144
135
mocked_bugzilla ,
145
136
):
146
137
mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
147
138
148
139
with mock .patch ("jbi.runner.Executor.__call__" , return_value = (True , {})):
149
- with caplog .at_level (logging .DEBUG ):
140
+ with capturelogs . for_logger ( "jbi.runner" ) .at_level (logging .DEBUG ):
150
141
execute_action (
151
142
request = webhook_create_example ,
152
143
actions = actions_example ,
153
144
)
154
145
155
- captured_log_msgs = [
156
- (r .msg % r .args , r .operation ) for r in caplog .records if r .name == "jbi.runner"
157
- ]
146
+ captured_log_msgs = [(r .getMessage (), r .operation ) for r in capturelogs .records ]
158
147
159
148
assert captured_log_msgs == [
160
149
("Handling incoming request" , Operation .HANDLE ),
@@ -164,28 +153,26 @@ def test_action_is_logged_as_success_if_returns_true(
164
153
),
165
154
("Action 'devtest' executed successfully for Bug 654321" , Operation .SUCCESS ),
166
155
]
167
- assert caplog .records [- 1 ].bug ["id" ] == 654321
168
- assert caplog .records [- 1 ].action ["whiteboard_tag" ] == "devtest"
156
+ assert capturelogs .records [- 1 ].bug ["id" ] == 654321
157
+ assert capturelogs .records [- 1 ].action ["whiteboard_tag" ] == "devtest"
169
158
170
159
171
160
def test_action_is_logged_as_ignore_if_returns_false (
172
- caplog ,
161
+ capturelogs ,
173
162
webhook_create_example : BugzillaWebhookRequest ,
174
163
actions_example : Actions ,
175
164
mocked_bugzilla ,
176
165
):
177
166
mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
178
167
179
168
with mock .patch ("jbi.runner.Executor.__call__" , return_value = (False , {})):
180
- with caplog .at_level (logging .DEBUG ):
169
+ with capturelogs . for_logger ( "jbi.runner" ) .at_level (logging .DEBUG ):
181
170
execute_action (
182
171
request = webhook_create_example ,
183
172
actions = actions_example ,
184
173
)
185
174
186
- captured_log_msgs = [
187
- (r .msg % r .args , r .operation ) for r in caplog .records if r .name == "jbi.runner"
188
- ]
175
+ captured_log_msgs = [(r .getMessage (), r .operation ) for r in capturelogs .records ]
189
176
190
177
assert captured_log_msgs == [
191
178
("Handling incoming request" , Operation .HANDLE ),
@@ -235,23 +222,20 @@ def test_runner_ignores_if_jira_issue_is_not_readable(
235
222
actions_example : Actions ,
236
223
mocked_bugzilla ,
237
224
mocked_jira ,
238
- caplog ,
225
+ capturelogs ,
239
226
):
240
227
mocked_jira .get_issue .return_value = None
241
228
mocked_bugzilla .get_bug .return_value = webhook_comment_example .bug
242
229
243
- with caplog .at_level (logging .DEBUG ):
230
+ with capturelogs . for_logger ( "jbi.runner" ) .at_level (logging .DEBUG ):
244
231
with pytest .raises (IgnoreInvalidRequestError ) as exc_info :
245
232
execute_action (
246
233
request = webhook_comment_example ,
247
234
actions = actions_example ,
248
235
)
249
236
250
237
assert str (exc_info .value ) == "ignore unreadable issue JBI-234"
251
- captured_log_msgs = [
252
- r .msg % r .args for r in caplog .records if r .name == "jbi.runner"
253
- ]
254
- assert captured_log_msgs == [
238
+ assert capturelogs .messages == [
255
239
"Handling incoming request" ,
256
240
"Ignore incoming request: ignore unreadable issue JBI-234" ,
257
241
]
@@ -306,7 +290,7 @@ def test_default_returns_callable_without_data(action_params_factory):
306
290
@pytest .mark .no_mocked_jira
307
291
def test_default_logs_all_received_responses (
308
292
mocked_responses ,
309
- caplog ,
293
+ capturelogs ,
310
294
context_comment_example : ActionContext ,
311
295
action_params_factory ,
312
296
):
@@ -330,11 +314,13 @@ def test_default_logs_all_received_responses(
330
314
)
331
315
)
332
316
333
- with caplog .at_level (logging .DEBUG ):
317
+ with capturelogs . for_logger ( "jbi.runner" ) .at_level (logging .DEBUG ):
334
318
action (context = context_comment_example )
335
319
336
320
captured_log_msgs = (
337
- (r .msg % r .args , r .response ) for r in caplog .records if r .name == "jbi.runner"
321
+ (r .msg % r .args , r .response )
322
+ for r in capturelogs .records
323
+ if r .name == "jbi.runner"
338
324
)
339
325
340
326
assert (
0 commit comments