blob: 9650cd6009132c26354edd2ca020af8afed87bfc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
"""
Test what happens if Python was built without SSL
* Everything that does not involve HTTPS should still work
* HTTPS requests must fail with an error that points at the ssl module
"""
import sys
from test import ImportBlocker, ModuleStash
import pytest
ssl_blocker = ImportBlocker("ssl", "_ssl")
module_stash = ModuleStash("urllib3")
class TestWithoutSSL:
@classmethod
def setup_class(cls):
sys.modules.pop("ssl", None)
sys.modules.pop("_ssl", None)
module_stash.stash()
sys.meta_path.insert(0, ssl_blocker)
def teardown_class(cls):
sys.meta_path.remove(ssl_blocker)
module_stash.pop()
class TestImportWithoutSSL(TestWithoutSSL):
def test_cannot_import_ssl(self):
with pytest.raises(ImportError):
import ssl # noqa: F401
def test_import_urllib3(self):
import urllib3 # noqa: F401
|