From 7f48f417d49bc66271483d7f733769d6e5bc6b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20de=20Saint=20Martin?= <cedric.dsm@tiolive.com> Date: Mon, 15 Sep 2014 10:45:07 +0000 Subject: [PATCH] slap test: make sure mocks/stubs are NOT leaking. --- slapos/tests/slap.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/slapos/tests/slap.py b/slapos/tests/slap.py index ee4042a2b..5e266fd6d 100644 --- a/slapos/tests/slap.py +++ b/slapos/tests/slap.py @@ -34,6 +34,9 @@ import urlparse import slapos.slap import xml_marshaller +ORIGINAL_HTTPLIB_HTTPCONNECTION = httplib.HTTPConnection +ORIGINAL_HTTPLIB_HTTPSCONNECTION = httplib.HTTPSConnection +ORIGINAL_HTTPLIB_HTTPRESPONSE = httplib.HTTPResponse class UndefinedYetException(Exception): """To catch exceptions which are not yet defined""" @@ -70,10 +73,17 @@ class SlapMixin(unittest.TestCase): def _unpatchHttplib(self): """Restores httplib overriding""" import httplib + + # XXX not reliable for name, original_value in self.saved_httplib.items(): setattr(httplib, name, original_value) del self.saved_httplib + # XXX this fixes upper code, to be sure it is reliable + httplib.HTTPConnection = ORIGINAL_HTTPLIB_HTTPCONNECTION + httplib.HTTPSConnection = ORIGINAL_HTTPLIB_HTTPSCONNECTION + httplib.HTTPResponse = ORIGINAL_HTTPLIB_HTTPRESPONSE + def _getTestComputerId(self): """ Returns the computer id used by the test @@ -987,3 +997,4 @@ if __name__ == '__main__': print 'You can point to any SLAP server by setting TEST_SLAP_SERVER_URL '\ 'environment variable' unittest.main() + -- 2.30.9