mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Fix last bit of of #109.
This commit is contained in:
@@ -151,7 +151,7 @@ def test_https_with_cert_validation_disabled(tmpdir):
|
|||||||
with vcr.use_cassette(str(tmpdir.join('cert_validation_disabled.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('cert_validation_disabled.yaml'))):
|
||||||
requests.get('https://httpbin.org', verify=False)
|
requests.get('https://httpbin.org', verify=False)
|
||||||
|
|
||||||
@pytest.mark.xfail
|
|
||||||
def test_session_can_make_requests_after_requests_unpatched(tmpdir):
|
def test_session_can_make_requests_after_requests_unpatched(tmpdir):
|
||||||
with vcr.use_cassette(str(tmpdir.join('test_session_after_unpatched.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('test_session_after_unpatched.yaml'))):
|
||||||
session = requests.session()
|
session = requests.session()
|
||||||
|
|||||||
16
vcr/patch.py
16
vcr/patch.py
@@ -124,10 +124,10 @@ class CassettePatcherBuilder(object):
|
|||||||
return ()
|
return ()
|
||||||
from .stubs.requests_stubs import VCRRequestsHTTPConnection, VCRRequestsHTTPSConnection
|
from .stubs.requests_stubs import VCRRequestsHTTPConnection, VCRRequestsHTTPSConnection
|
||||||
http_connection_remover = ConnectionRemover(
|
http_connection_remover = ConnectionRemover(
|
||||||
self._get_cassette_subclass(VCRHTTPConnection)
|
self._get_cassette_subclass(VCRRequestsHTTPConnection)
|
||||||
)
|
)
|
||||||
https_connection_remover = ConnectionRemover(
|
https_connection_remover = ConnectionRemover(
|
||||||
self._get_cassette_subclass(VCRHTTPSConnection)
|
self._get_cassette_subclass(VCRRequestsHTTPSConnection)
|
||||||
)
|
)
|
||||||
mock_triples = (
|
mock_triples = (
|
||||||
(cpool, 'VerifiedHTTPSConnection', VCRRequestsHTTPSConnection),
|
(cpool, 'VerifiedHTTPSConnection', VCRRequestsHTTPSConnection),
|
||||||
@@ -149,7 +149,7 @@ class CassettePatcherBuilder(object):
|
|||||||
self._patched_new_conn(cpool.HTTPConnectionPool,
|
self._patched_new_conn(cpool.HTTPConnectionPool,
|
||||||
http_connection_remover)),
|
http_connection_remover)),
|
||||||
(cpool.HTTPSConnectionPool, '_new_conn',
|
(cpool.HTTPSConnectionPool, '_new_conn',
|
||||||
self._patched_new_conn(cpool.HTTPConnectionPool,
|
self._patched_new_conn(cpool.HTTPSConnectionPool,
|
||||||
https_connection_remover)))
|
https_connection_remover)))
|
||||||
|
|
||||||
return itertools.chain(self._build_patchers_from_mock_triples(mock_triples),
|
return itertools.chain(self._build_patchers_from_mock_triples(mock_triples),
|
||||||
@@ -222,11 +222,11 @@ class ConnectionRemover(object):
|
|||||||
|
|
||||||
def add_connection_to_pool_entry(self, pool, connection):
|
def add_connection_to_pool_entry(self, pool, connection):
|
||||||
if isinstance(connection, self._connection_class):
|
if isinstance(connection, self._connection_class):
|
||||||
self._connection_pool_to_connection.setdefault(pool, set()).add(connection)
|
self._connection_pool_to_connections.setdefault(pool, set()).add(connection)
|
||||||
|
|
||||||
def remove_connection_to_pool_entry(self, pool, connection):
|
def remove_connection_to_pool_entry(self, pool, connection):
|
||||||
if isinstance(connection, self._connection_class):
|
if isinstance(connection, self._connection_class):
|
||||||
self._connection_pool_to_connection[self._connection_class].remove(connection)
|
self._connection_pool_to_connections[self._connection_class].remove(connection)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
@@ -234,14 +234,14 @@ class ConnectionRemover(object):
|
|||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
for pool, connections in self._connection_pool_to_connections.items():
|
for pool, connections in self._connection_pool_to_connections.items():
|
||||||
readd_connections = []
|
readd_connections = []
|
||||||
while pool.not_empty() and connections:
|
while not pool.pool.empty() and connections:
|
||||||
connection = pool.get()
|
connection = pool.pool.get()
|
||||||
if isinstance(connection, self._connection_class):
|
if isinstance(connection, self._connection_class):
|
||||||
connections.remove(connection)
|
connections.remove(connection)
|
||||||
else:
|
else:
|
||||||
readd_connections.append(connection)
|
readd_connections.append(connection)
|
||||||
for connection in readd_connections:
|
for connection in readd_connections:
|
||||||
self.pool._put_conn(connection)
|
pool._put_conn(connection)
|
||||||
|
|
||||||
|
|
||||||
def reset_patchers():
|
def reset_patchers():
|
||||||
|
|||||||
Reference in New Issue
Block a user