]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Only have a sock attribute after connecting
authorSamuel Fekete <samuel.fekete@hogarthww.com>
Mon, 3 Jul 2017 15:54:29 +0000 (16:54 +0100)
committerSamuel Fekete <samuel.fekete@gmail.com>
Fri, 13 Jul 2018 15:40:35 +0000 (16:40 +0100)
vcr/stubs/__init__.py

index 763204ee5639ce39268b9410c5f38d5883daa1cc..a23a731f9babead37411c827b9cd0882ed2e6b13 100644 (file)
@@ -171,6 +171,8 @@ class VCRConnection(object):
         # allows me to compare the entire length of the response to see if it
         # exists in the cassette.
 
+        self._sock = VCRFakeSocket()
+
     def putrequest(self, method, url, *args, **kwargs):
         """
         httplib gives you more than one way to do it.  This is a way
@@ -294,11 +296,13 @@ class VCRConnection(object):
         with force_reset():
             return self.real_connection.connect(*args, **kwargs)
 
+        self._sock = VCRFakeSocket()
+
     @property
     def sock(self):
         if self.real_connection.sock:
             return self.real_connection.sock
-        return VCRFakeSocket()
+        return self._sock
 
     @sock.setter
     def sock(self, value):
@@ -316,6 +320,8 @@ class VCRConnection(object):
         with force_reset():
             self.real_connection = self._baseclass(*args, **kwargs)
 
+        self._sock = None
+
     def __setattr__(self, name, value):
         """
         We need to define this because any attributes that are set on the