diff --git a/tests/integration/test_boto3.py b/tests/integration/test_boto3.py index cff712a..0bdb6a0 100644 --- a/tests/integration/test_boto3.py +++ b/tests/integration/test_boto3.py @@ -57,25 +57,6 @@ def get_user(iam_client): return _get_user -@boto3_skip_vendored_requests -def test_boto_vendored_stubs(tmpdir): - with vcr.use_cassette(str(tmpdir.join("boto3-stubs.yml"))): - # Perform the imports within the patched context so that - # HTTPConnection, VerifiedHTTPSConnection refers to the patched version. - from botocore.vendored.requests.packages.urllib3.connectionpool import ( - HTTPConnection, - VerifiedHTTPSConnection, - ) - - from vcr.stubs.boto3_stubs import VCRRequestsHTTPConnection, VCRRequestsHTTPSConnection - - # Prove that the class was patched by the stub and that we can instantiate it. - assert issubclass(HTTPConnection, VCRRequestsHTTPConnection) - assert issubclass(VerifiedHTTPSConnection, VCRRequestsHTTPSConnection) - HTTPConnection("hostname.does.not.matter") - VerifiedHTTPSConnection("hostname.does.not.matter") - - @pytest.mark.skipif( os.environ.get("TRAVIS_PULL_REQUEST") != "false", reason="Encrypted Environment Variables from Travis Repository Settings" diff --git a/vcr/patch.py b/vcr/patch.py index a283287..169d194 100644 --- a/vcr/patch.py +++ b/vcr/patch.py @@ -16,15 +16,16 @@ _HTTPSConnection = httplib.HTTPSConnection # Try to save the original types for boto3 try: from botocore.awsrequest import AWSHTTPConnection, AWSHTTPSConnection -except ImportError: +except ImportError as e: try: - import botocore.vendored.requests.packages.urllib3.connectionpool as cpool + import botocore.vendored.requests # noqa: F401 except ImportError: # pragma: no cover pass else: - _Boto3VerifiedHTTPSConnection = cpool.VerifiedHTTPSConnection - _cpoolBoto3HTTPConnection = cpool.HTTPConnection - _cpoolBoto3HTTPSConnection = cpool.HTTPSConnection + raise RuntimeError( + "vcrpy >=4.2.2 and botocore <1.11.0 are not compatible" + "; please upgrade botocore (or downgrade vcrpy)" + ) from e else: _Boto3VerifiedHTTPSConnection = AWSHTTPSConnection _cpoolBoto3HTTPConnection = AWSHTTPConnection @@ -203,15 +204,7 @@ class CassettePatcherBuilder: # botocore using awsrequest import botocore.awsrequest as cpool except ImportError: # pragma: no cover - try: - # botocore using vendored requests - import botocore.vendored.requests.packages.urllib3.connectionpool as cpool - except ImportError: # pragma: no cover - pass - else: - from .stubs import boto3_stubs - - yield self._urllib3_patchers(cpool, boto3_stubs) + pass else: from .stubs import boto3_stubs @@ -460,24 +453,7 @@ def reset_patchers(): # unpatch botocore with awsrequest import botocore.awsrequest as cpool except ImportError: # pragma: no cover - try: - # unpatch botocore with vendored requests - import botocore.vendored.requests.packages.urllib3.connectionpool as cpool - except ImportError: # pragma: no cover - pass - else: - # unpatch requests v1.x - yield mock.patch.object(cpool, "VerifiedHTTPSConnection", _Boto3VerifiedHTTPSConnection) - yield mock.patch.object(cpool, "HTTPConnection", _cpoolBoto3HTTPConnection) - # unpatch requests v2.x - if hasattr(cpool.HTTPConnectionPool, "ConnectionCls"): - yield mock.patch.object(cpool.HTTPConnectionPool, "ConnectionCls", _cpoolBoto3HTTPConnection) - yield mock.patch.object( - cpool.HTTPSConnectionPool, "ConnectionCls", _cpoolBoto3HTTPSConnection - ) - - if hasattr(cpool, "HTTPSConnection"): - yield mock.patch.object(cpool, "HTTPSConnection", _cpoolBoto3HTTPSConnection) + pass else: if hasattr(cpool.AWSHTTPConnectionPool, "ConnectionCls"): yield mock.patch.object(cpool.AWSHTTPConnectionPool, "ConnectionCls", _cpoolBoto3HTTPConnection) diff --git a/vcr/stubs/boto3_stubs.py b/vcr/stubs/boto3_stubs.py index a4d349a..37fd9e3 100644 --- a/vcr/stubs/boto3_stubs.py +++ b/vcr/stubs/boto3_stubs.py @@ -1,17 +1,6 @@ """Stubs for boto3""" -try: - # boto using awsrequest - from botocore.awsrequest import AWSHTTPConnection as HTTPConnection - from botocore.awsrequest import AWSHTTPSConnection as VerifiedHTTPSConnection - -except ImportError: # pragma: nocover - # boto using vendored requests - # urllib3 defines its own HTTPConnection classes, which boto3 goes ahead and assumes - # you're using. It includes some polyfills for newer features missing in older pythons. - try: - from urllib3.connectionpool import HTTPConnection, VerifiedHTTPSConnection - except ImportError: # pragma: nocover - from requests.packages.urllib3.connectionpool import HTTPConnection, VerifiedHTTPSConnection +from botocore.awsrequest import AWSHTTPConnection as HTTPConnection +from botocore.awsrequest import AWSHTTPSConnection as VerifiedHTTPSConnection from ..stubs import VCRHTTPConnection, VCRHTTPSConnection