Issue #12804: Fix test failures on systems without internet access.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Wed, 25 Jan 2012 06:02:05 +0000 (08:02 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Wed, 25 Jan 2012 06:02:05 +0000 (08:02 +0200)
Lib/test/test_socket.py
Lib/test/test_urllib2net.py
Misc/NEWS

index d277e36cd2b973c72ae4d0044dce080d9272e9a3..ede1038662e9fc0d553c5b6be6f51ed54b2017ab 100644 (file)
@@ -1168,6 +1168,12 @@ class GeneralModuleTests(unittest.TestCase):
     @unittest.skipUnless(support.is_resource_enabled('network'),
                          'network is not enabled')
     def test_idna(self):
+        # Check for internet access before running test (issue #12804).
+        try:
+            socket.gethostbyname('python.org')
+        except socket.gaierror as e:
+            if e.errno == socket.EAI_NODATA:
+                self.skipTest('internet access required for this test')
         # these should all be successful
         socket.gethostbyname('испытание.python.org')
         socket.gethostbyname_ex('испытание.python.org')
index 5fcb4cbca20f94a40a4b04f4a288779934e1d496..fc5527ee872e6c0370665b493786f5cebd6c54bd 100644 (file)
@@ -83,12 +83,13 @@ class CloseSocketTest(unittest.TestCase):
     def test_close(self):
         # calling .close() on urllib2's response objects should close the
         # underlying socket
-
-        response = _urlopen_with_retry("http://www.python.org/")
-        sock = response.fp
-        self.assertTrue(not sock.closed)
-        response.close()
-        self.assertTrue(sock.closed)
+        url = "http://www.python.org/"
+        with support.transient_internet(url):
+            response = _urlopen_with_retry(url)
+            sock = response.fp
+            self.assertTrue(not sock.closed)
+            response.close()
+            self.assertTrue(sock.closed)
 
 class OtherNetworkTests(unittest.TestCase):
     def setUp(self):
index 9c34ac8c1cfbd49c2e94574c0a00d3bd0582a7d3..f6b1f0db3a90c9b52d8c9f0dcb68ea3ee01144fd 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -461,6 +461,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #12804: Fix test_socket and test_urllib2net failures when running tests
+  on a system without internet access.
+
 - Issue #13772: In os.symlink() under Windows, do not try to guess the link
   target's type (file or directory).  The detection was buggy and made the
   call non-atomic (therefore prone to race conditions).