Skip to content

Commit 3481865

Browse files
committed
Use keyword arguments for pytest raises
1 parent 79302f4 commit 3481865

10 files changed

+40
-28
lines changed

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def not_base64_encoded_processable(request: pytest.FixtureRequest) -> str:
140140
"""
141141
not_base64_encoded_string: str = request.param
142142

143-
with pytest.raises(binascii.Error):
143+
with pytest.raises(expected_exception=binascii.Error):
144144
base64.b64decode(s=not_base64_encoded_string, validate=True)
145145

146146
return not_base64_encoded_string
@@ -162,7 +162,7 @@ def not_base64_encoded_not_processable(request: pytest.FixtureRequest) -> str:
162162
"""
163163
not_base64_encoded_string: str = request.param
164164

165-
with pytest.raises(binascii.Error):
165+
with pytest.raises(expected_exception=binascii.Error):
166166
base64.b64decode(s=not_base64_encoded_string, validate=True)
167167

168168
return not_base64_encoded_string

tests/mock_vws/test_authorization_header.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_bad_access_key_services(
216216
server_secret_key=vuforia_database.server_secret_key,
217217
)
218218

219-
with pytest.raises(Fail) as exc:
219+
with pytest.raises(expected_exception=Fail) as exc:
220220
vws_client.get_target_record(target_id=uuid.uuid4().hex)
221221

222222
assert exc.value.response.status_code == HTTPStatus.BAD_REQUEST
@@ -235,7 +235,9 @@ def test_bad_access_key_query(
235235
client_secret_key=vuforia_database.client_secret_key,
236236
)
237237

238-
with pytest.raises(cloud_reco_exceptions.AuthenticationFailure) as exc:
238+
with pytest.raises(
239+
expected_exception=cloud_reco_exceptions.AuthenticationFailure
240+
) as exc:
239241
cloud_reco_client.query(image=high_quality_image)
240242

241243
response = exc.value.response
@@ -279,7 +281,7 @@ def test_bad_secret_key_services(
279281
server_secret_key="example",
280282
)
281283

282-
with pytest.raises(AuthenticationFailure):
284+
with pytest.raises(expected_exception=AuthenticationFailure):
283285
vws_client.get_target_record(target_id=uuid.uuid4().hex)
284286

285287
@staticmethod
@@ -296,7 +298,9 @@ def test_bad_secret_key_query(
296298
client_secret_key="example",
297299
)
298300

299-
with pytest.raises(cloud_reco_exceptions.AuthenticationFailure) as exc:
301+
with pytest.raises(
302+
expected_exception=cloud_reco_exceptions.AuthenticationFailure
303+
) as exc:
300304
cloud_reco_client.query(image=high_quality_image)
301305

302306
response = exc.value.response

tests/mock_vws/test_database_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def test_bad_target_request(
384384
report = vws_client.get_database_summary_report()
385385
original_request_usage = report.request_usage
386386

387-
with pytest.raises(Fail) as exc:
387+
with pytest.raises(expected_exception=Fail) as exc:
388388
vws_client.add_target(
389389
name="example",
390390
width=-1,

tests/mock_vws/test_delete_target.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_no_wait(target_id: str, vws_client: VWS) -> None:
3838
There is a race condition here - if the target goes into a success or
3939
fail state before the deletion attempt.
4040
"""
41-
with pytest.raises(TargetStatusProcessing) as exc:
41+
with pytest.raises(expected_exception=TargetStatusProcessing) as exc:
4242
vws_client.delete_target(target_id=target_id)
4343

4444
assert_vws_failure(
@@ -55,7 +55,7 @@ def test_processed(target_id: str, vws_client: VWS) -> None:
5555
vws_client.wait_for_target_processed(target_id=target_id)
5656
vws_client.delete_target(target_id=target_id)
5757

58-
with pytest.raises(UnknownTarget):
58+
with pytest.raises(expected_exception=UnknownTarget):
5959
vws_client.get_target_record(target_id=target_id)
6060

6161

@@ -71,7 +71,7 @@ def test_inactive_project(inactive_vws_client: VWS) -> None:
7171
If the project is inactive, a FORBIDDEN response is returned.
7272
"""
7373
target_id = "abc12345a"
74-
with pytest.raises(ProjectInactive) as exc:
74+
with pytest.raises(expected_exception=ProjectInactive) as exc:
7575
inactive_vws_client.delete_target(target_id=target_id)
7676

7777
assert_vws_failure(

tests/mock_vws/test_get_duplicates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def test_inactive_project(inactive_vws_client: VWS) -> None:
269269
"""
270270
If the project is inactive, a FORBIDDEN response is returned.
271271
"""
272-
with pytest.raises(ProjectInactive):
272+
with pytest.raises(expected_exception=ProjectInactive):
273273
inactive_vws_client.get_duplicate_targets(
274274
target_id=uuid.uuid4().hex,
275275
)

tests/mock_vws/test_get_target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,5 @@ def test_inactive_project(inactive_vws_client: VWS) -> None:
187187
"""
188188
The project's active state does not affect getting a target.
189189
"""
190-
with pytest.raises(UnknownTarget):
190+
with pytest.raises(expected_exception=UnknownTarget):
191191
inactive_vws_client.get_target_record(target_id=uuid.uuid4().hex)

tests/mock_vws/test_query.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ def test_not_image(cloud_reco_client: CloudRecoService) -> None:
12731273
"""
12741274
not_image_data = b"not_image_data"
12751275

1276-
with pytest.raises(BadImage) as exc_info:
1276+
with pytest.raises(expected_exception=BadImage) as exc_info:
12771277
cloud_reco_client.query(
12781278
image=io.BytesIO(initial_bytes=not_image_data)
12791279
)
@@ -1370,7 +1370,9 @@ def test_png(
13701370
assert image_content_size > max_bytes
13711371
assert (image_content_size * 0.95) < max_bytes
13721372

1373-
with pytest.raises(RequestEntityTooLarge) as exc_info:
1373+
with pytest.raises(
1374+
expected_exception=RequestEntityTooLarge
1375+
) as exc_info:
13741376
cloud_reco_client.query(image=png_too_large)
13751377

13761378
response = exc_info.value.response
@@ -1447,7 +1449,9 @@ def test_jpeg(
14471449
assert image_content_size > max_bytes
14481450
assert (image_content_size * 0.95) < max_bytes
14491451

1450-
with pytest.raises(RequestEntityTooLarge) as exc_info:
1452+
with pytest.raises(
1453+
expected_exception=RequestEntityTooLarge
1454+
) as exc_info:
14511455
cloud_reco_client.query(image=jpeg_too_large)
14521456

14531457
response = exc_info.value.response
@@ -1497,7 +1501,7 @@ def test_max_height(
14971501
height=max_height + 1,
14981502
)
14991503

1500-
with pytest.raises(BadImage) as exc_info:
1504+
with pytest.raises(expected_exception=BadImage) as exc_info:
15011505
cloud_reco_client.query(image=png_too_tall)
15021506

15031507
response = exc_info.value.response
@@ -1550,7 +1554,7 @@ def test_max_width(cloud_reco_client: CloudRecoService) -> None:
15501554
height=height,
15511555
)
15521556

1553-
with pytest.raises(BadImage) as exc_info:
1557+
with pytest.raises(expected_exception=BadImage) as exc_info:
15541558
result = cloud_reco_client.query(image=png_too_wide)
15551559

15561560
response = exc_info.value.response
@@ -1634,7 +1638,7 @@ def test_unsupported(
16341638
pil_image.save(image_buffer, file_format)
16351639
image_content = image_buffer.getvalue()
16361640

1637-
with pytest.raises(BadImage) as exc_info:
1641+
with pytest.raises(expected_exception=BadImage) as exc_info:
16381642
cloud_reco_client.query(
16391643
image=io.BytesIO(initial_bytes=image_content)
16401644
)
@@ -1977,7 +1981,7 @@ def test_inactive_project(
19771981
"""
19781982
If the project is inactive, a FORBIDDEN response is returned.
19791983
"""
1980-
with pytest.raises(InactiveProject) as exc_info:
1984+
with pytest.raises(expected_exception=InactiveProject) as exc_info:
19811985
inactive_cloud_reco_client.query(image=high_quality_image)
19821986

19831987
response = exc_info.value.response

tests/mock_vws/test_requests_mock_usage.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,17 @@ def test_default() -> None:
8181
non-Vuforia addresses, but not to mocked Vuforia endpoints.
8282
"""
8383
with MockVWS():
84-
with pytest.raises(NoMockAddress):
84+
with pytest.raises(expected_exception=NoMockAddress):
8585
request_unmocked_address()
8686

8787
# No exception is raised when making a request to a mocked
8888
# endpoint.
8989
request_mocked_address()
9090

9191
# The mocking stops when the context manager stops.
92-
with pytest.raises(requests.exceptions.ConnectionError):
92+
with pytest.raises(
93+
expected_exception=requests.exceptions.ConnectionError
94+
):
9395
request_unmocked_address()
9496

9597
@staticmethod
@@ -100,7 +102,9 @@ def test_real_http() -> None:
100102
"""
101103
with (
102104
MockVWS(real_http=True),
103-
pytest.raises(requests.exceptions.ConnectionError),
105+
pytest.raises(
106+
expected_exception=requests.exceptions.ConnectionError
107+
),
104108
):
105109
request_unmocked_address()
106110

@@ -186,7 +190,7 @@ def test_custom_base_vws_url() -> None:
186190
base_vws_url="https://vuforia.vws.example.com",
187191
real_http=False,
188192
):
189-
with pytest.raises(NoMockAddress):
193+
with pytest.raises(expected_exception=NoMockAddress):
190194
requests.get(url="https://vws.vuforia.com/summary", timeout=30)
191195

192196
requests.get(
@@ -207,7 +211,7 @@ def test_custom_base_vwq_url() -> None:
207211
base_vwq_url="https://vuforia.vwq.example.com",
208212
real_http=False,
209213
):
210-
with pytest.raises(NoMockAddress):
214+
with pytest.raises(expected_exception=NoMockAddress):
211215
requests.post(
212216
url="https://cloudreco.vuforia.com/v1/query",
213217
timeout=30,
@@ -227,15 +231,15 @@ def test_no_scheme() -> None:
227231
"""
228232
An error if raised if a URL is given with no scheme.
229233
"""
230-
with pytest.raises(MissingSchema) as vws_exc:
234+
with pytest.raises(expected_exception=MissingSchema) as vws_exc:
231235
MockVWS(base_vws_url="vuforia.vws.example.com")
232236

233237
expected = (
234238
'Invalid URL "vuforia.vws.example.com": No scheme supplied. '
235239
'Perhaps you meant "https://vuforia.vws.example.com".'
236240
)
237241
assert str(vws_exc.value) == expected
238-
with pytest.raises(MissingSchema) as vwq_exc:
242+
with pytest.raises(expected_exception=MissingSchema) as vwq_exc:
239243
MockVWS(base_vwq_url="vuforia.vwq.example.com")
240244
expected = (
241245
'Invalid URL "vuforia.vwq.example.com": No scheme supplied. '

tests/mock_vws/test_target_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def test_inactive_project(inactive_vws_client: VWS) -> None:
173173
"""
174174
The project's active state does not affect getting a target.
175175
"""
176-
with pytest.raises(UnknownTarget):
176+
with pytest.raises(expected_exception=UnknownTarget):
177177
inactive_vws_client.get_target_summary_report(
178178
target_id=uuid.uuid4().hex,
179179
)

tests/mock_vws/test_update_target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,5 +902,5 @@ def test_inactive_project(inactive_vws_client: VWS) -> None:
902902
"""
903903
If the project is inactive, a FORBIDDEN response is returned.
904904
"""
905-
with pytest.raises(ProjectInactive):
905+
with pytest.raises(expected_exception=ProjectInactive):
906906
inactive_vws_client.update_target(target_id=uuid.uuid4().hex)

0 commit comments

Comments
 (0)