From 15585909c3dd3014e4083961c8a404709450151c Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Sat, 21 Jan 2023 09:44:33 +0100 Subject: [PATCH] Support missing SNIMissingWarning in tests (#6336) --- tests/__init__.py | 14 +++++++++----- tests/test_requests.py | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 04385be18a..c8561a0801 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,9 +2,13 @@ import warnings -from urllib3.exceptions import SNIMissingWarning +try: + from urllib3.exceptions import SNIMissingWarning -# urllib3 sets SNIMissingWarning to only go off once, -# while this test suite requires it to always fire -# so that it occurs during test_requests.test_https_warnings -warnings.simplefilter("always", SNIMissingWarning) + # urllib3 1.x sets SNIMissingWarning to only go off once, + # while this test suite requires it to always fire + # so that it occurs during test_requests.test_https_warnings + warnings.simplefilter("always", SNIMissingWarning) +except ImportError: + # urllib3 2.0 removed that warning and errors out instead + SNIMissingWarning = None diff --git a/tests/test_requests.py b/tests/test_requests.py index 5b4c3f53fa..2a5c9b1102 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -48,6 +48,7 @@ from requests.sessions import SessionRedirectMixin from requests.structures import CaseInsensitiveDict +from . import SNIMissingWarning from .compat import StringIO from .utils import override_environ @@ -974,6 +975,10 @@ def test_http_with_certificate(self, httpbin): r = requests.get(httpbin(), cert=".") assert r.status_code == 200 + @pytest.mark.skipif( + SNIMissingWarning is None, + reason="urllib3 2.0 removed that warning and errors out instead", + ) def test_https_warnings(self, nosan_server): """warnings are emitted with requests.get""" host, port, ca_bundle = nosan_server