diff --git a/tests/integration/test_urllib3.py b/tests/integration/test_urllib3.py index 0c02c40..2884d35 100644 --- a/tests/integration/test_urllib3.py +++ b/tests/integration/test_urllib3.py @@ -5,8 +5,10 @@ import pytest import pytest_httpbin import vcr +from vcr.patch import force_reset from assertions import assert_cassette_empty, assert_is_json urllib3 = pytest.importorskip("urllib3") +cpool = pytest.importorskip("urllib3.connectionpool") @pytest.fixture(scope='module') @@ -138,3 +140,20 @@ def test_gzip(tmpdir, httpbin_both, verify_pool_mgr): def test_https_with_cert_validation_disabled(tmpdir, httpbin_secure, pool_mgr): with vcr.use_cassette(str(tmpdir.join('cert_validation_disabled.yaml'))): pool_mgr.request('GET', httpbin_secure.url) + + +def test_urllib3_force_reset(): + http_original = cpool.HTTPConnection + https_original = cpool.HTTPSConnection + verified_https_original = cpool.VerifiedHTTPSConnection + with vcr.use_cassette(path='test'): + first_cassette_HTTPConnection = cpool.HTTPConnection + first_cassette_HTTPSConnection = cpool.HTTPSConnection + first_cassette_VerifiedHTTPSConnection = cpool.VerifiedHTTPSConnection + with force_reset(): + assert cpool.HTTPConnection is http_original + assert cpool.HTTPSConnection is https_original + assert cpool.VerifiedHTTPSConnection is verified_https_original + assert cpool.HTTPConnection is first_cassette_HTTPConnection + assert cpool.HTTPSConnection is first_cassette_HTTPSConnection + assert cpool.VerifiedHTTPSConnection is first_cassette_VerifiedHTTPSConnection diff --git a/vcr/patch.py b/vcr/patch.py index bc93ad9..434e45c 100644 --- a/vcr/patch.py +++ b/vcr/patch.py @@ -386,11 +386,11 @@ def reset_patchers(): pass else: yield mock.patch.object(cpool, 'VerifiedHTTPSConnection', _VerifiedHTTPSConnection) - yield mock.patch.object(cpool, 'HTTPConnection', _HTTPConnection) - yield mock.patch.object(cpool, 'HTTPSConnection', _HTTPSConnection) + yield mock.patch.object(cpool, 'HTTPConnection', _cpoolHTTPConnection) + yield mock.patch.object(cpool, 'HTTPSConnection', _cpoolHTTPSConnection) if hasattr(cpool.HTTPConnectionPool, 'ConnectionCls'): - yield mock.patch.object(cpool.HTTPConnectionPool, 'ConnectionCls', _HTTPConnection) - yield mock.patch.object(cpool.HTTPSConnectionPool, 'ConnectionCls', _HTTPSConnection) + yield mock.patch.object(cpool.HTTPConnectionPool, 'ConnectionCls', _cpoolHTTPConnection) + yield mock.patch.object(cpool.HTTPSConnectionPool, 'ConnectionCls', _cpoolHTTPSConnection) try: import botocore.vendored.requests.packages.urllib3.connectionpool as cpool