@@ -283,9 +283,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
283283 check = CloudFoundryApiCheck ('cloud_foundry_api' , {}, [instance ])
284284 check ._http = None # initialize the _http attribute for mocking
285285
286- with mock .patch .object (check , "_http" ) as http_mock , pytest . raises ( RequestException ) :
286+ with mock .patch .object (check , "_http" ) as http_mock :
287287 http_mock .get .side_effect = RequestException ()
288- check .get_oauth_token ()
288+ with pytest .raises (RequestException ):
289+ check .get_oauth_token ()
289290 aggregator .assert_service_check (
290291 name = "cloud_foundry_api.uaa.can_authenticate" ,
291292 status = CloudFoundryApiCheck .CRITICAL ,
@@ -294,9 +295,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
294295 )
295296 aggregator .reset ()
296297
297- with mock .patch .object (check , "_http" ) as http_mock , pytest . raises ( HTTPError ) :
298+ with mock .patch .object (check , "_http" ) as http_mock :
298299 http_mock .get .return_value = mock .MagicMock (raise_for_status = mock .MagicMock (side_effect = HTTPError ()))
299- check .get_oauth_token ()
300+ with pytest .raises (HTTPError ):
301+ check .get_oauth_token ()
300302 aggregator .assert_service_check (
301303 name = "cloud_foundry_api.uaa.can_authenticate" ,
302304 status = CloudFoundryApiCheck .CRITICAL ,
@@ -305,9 +307,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
305307 )
306308 aggregator .reset ()
307309
308- with mock .patch .object (check , "_http" ) as http_mock , pytest . raises ( ValueError ) :
310+ with mock .patch .object (check , "_http" ) as http_mock :
309311 http_mock .get .return_value = mock .MagicMock (json = mock .MagicMock (side_effect = ValueError ()))
310- check .get_oauth_token ()
312+ with pytest .raises (ValueError ):
313+ check .get_oauth_token ()
311314 aggregator .assert_service_check (
312315 name = "cloud_foundry_api.uaa.can_authenticate" ,
313316 status = CloudFoundryApiCheck .CRITICAL ,
0 commit comments