]> granicus.if.org Git - python/commitdiff
test_urllibnet: make it so that transient_internet() applies to the
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 26 Mar 2011 17:36:42 +0000 (18:36 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 26 Mar 2011 17:36:42 +0000 (18:36 +0100)
whole HTTP exchange, not only the opening.

Lib/test/test_urllibnet.py

index c8851031e894b30f316cbfccd317a92ba13b402c..a019ddd2a6a9071062fb5dafadb17dcb07c9de8a 100644 (file)
@@ -43,8 +43,10 @@ class urlopenNetworkTests(unittest.TestCase):
 
     def urlopen(self, *args, **kwargs):
         resource = args[0]
-        with support.transient_internet(resource):
-            return urllib.request.urlopen(*args, **kwargs)
+        cm = support.transient_internet(resource)
+        cm.__enter__()
+        self.addCleanup(cm.__exit__, None, None, None)
+        return urllib.request.urlopen(*args, **kwargs)
 
     def test_basic(self):
         # Simple test expected to pass.
@@ -135,8 +137,10 @@ class urlretrieveNetworkTests(unittest.TestCase):
 
     def urlretrieve(self, *args):
         resource = args[0]
-        with support.transient_internet(resource):
-            return urllib.request.urlretrieve(*args)
+        cm = support.transient_internet(resource)
+        cm.__enter__()
+        self.addCleanup(cm.__exit__, None, None, None)
+        return urllib.request.urlretrieve(*args)
 
     def test_basic(self):
         # Test basic functionality.