Skip to content

Commit

Permalink
Support missing SNIMissingWarning in tests (#6336)
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed Jan 21, 2023
1 parent 16a17a3 commit 1558590
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/__init__.py
Expand Up @@ -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
5 changes: 5 additions & 0 deletions tests/test_requests.py
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1558590

Please sign in to comment.