From 0ef5274a3c6189e8fa6a7d97993c165ab548fe95 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 10 Jan 2022 09:02:20 -0600 Subject: [PATCH] Don't assert stdlib behavior, just assert that urllib was called --- .../module_utils/urls/test_RedirectHandlerFactory.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/units/module_utils/urls/test_RedirectHandlerFactory.py b/test/units/module_utils/urls/test_RedirectHandlerFactory.py index aa3500a15c2..7bbe4b5b334 100644 --- a/test/units/module_utils/urls/test_RedirectHandlerFactory.py +++ b/test/units/module_utils/urls/test_RedirectHandlerFactory.py @@ -130,9 +130,11 @@ def test_redir_validate_certs(urllib_req, request_body, mocker): assert opener_mock.add_handler.call_count == int(not HAS_SSLCONTEXT) -def test_redir_http_error_308_urllib2(urllib_req, request_body): +def test_redir_http_error_308_urllib2(urllib_req, request_body, mocker): + redir_mock = mocker.patch.object(urllib_request.HTTPRedirectHandler, 'redirect_request') handler = RedirectHandlerFactory('urllib2', False) inst = handler() - with pytest.raises(urllib_error.HTTPError): - inst.redirect_request(urllib_req, request_body, 308, '308 Permanent Redirect', {}, 'https://docs.ansible.com/') + inst.redirect_request(urllib_req, request_body, 308, '308 Permanent Redirect', {}, 'https://docs.ansible.com/') + + assert redir_mock.call_count == 1