Skip to content

Commit 1558590

Browse files
authored
Support missing SNIMissingWarning in tests (#6336)
1 parent 16a17a3 commit 1558590

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

tests/__init__.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import warnings
44

5-
from urllib3.exceptions import SNIMissingWarning
5+
try:
6+
from urllib3.exceptions import SNIMissingWarning
67

7-
# urllib3 sets SNIMissingWarning to only go off once,
8-
# while this test suite requires it to always fire
9-
# so that it occurs during test_requests.test_https_warnings
10-
warnings.simplefilter("always", SNIMissingWarning)
8+
# urllib3 1.x sets SNIMissingWarning to only go off once,
9+
# while this test suite requires it to always fire
10+
# so that it occurs during test_requests.test_https_warnings
11+
warnings.simplefilter("always", SNIMissingWarning)
12+
except ImportError:
13+
# urllib3 2.0 removed that warning and errors out instead
14+
SNIMissingWarning = None

tests/test_requests.py

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from requests.sessions import SessionRedirectMixin
4949
from requests.structures import CaseInsensitiveDict
5050

51+
from . import SNIMissingWarning
5152
from .compat import StringIO
5253
from .utils import override_environ
5354

@@ -974,6 +975,10 @@ def test_http_with_certificate(self, httpbin):
974975
r = requests.get(httpbin(), cert=".")
975976
assert r.status_code == 200
976977

978+
@pytest.mark.skipif(
979+
SNIMissingWarning is None,
980+
reason="urllib3 2.0 removed that warning and errors out instead",
981+
)
977982
def test_https_warnings(self, nosan_server):
978983
"""warnings are emitted with requests.get"""
979984
host, port, ca_bundle = nosan_server

0 commit comments

Comments
 (0)