From eb4774a7d2252789f34801d9026e3d3cabd3be03 Mon Sep 17 00:00:00 2001 From: Samuel Fekete Date: Mon, 3 Jul 2017 16:54:29 +0100 Subject: [PATCH] Only have a sock attribute after connecting --- vcr/stubs/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index 763204e..a23a731 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -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