from __future__ import absolute_import, print_function

import unittest
import sys

class ImportUrllibTest(unittest.TestCase):
    def test_urllib(self):
        """
        This should perhaps fail: importing urllib first means that the import hooks
        won't be consulted when importing urllib.response.
        """
        import urllib
        print(urllib.__file__)
        from future import standard_library
        with standard_library.hooks():
            import urllib.response
        print(urllib.__file__)
        print(urllib.response.__file__)

if __name__ == '__main__':
    unittest.main()

from __future__ import absolute_import, print_function

import unittest
import sys

class ImportUrllibTest(unittest.TestCase):
    def test_urllib(self):
        import urllib
        orig_file = urllib.__file__
        from future.standard_library.urllib import response as urllib_response
        self.assertEqual(orig_file, urllib.__file__)
        print(urllib_response.__file__)

if __name__ == '__main__':
    unittest.main()

Change urllib test to use an explicit import
Change urllib test to use an explicit import

  from __future__ import absolute_import, print_function
  
  import unittest
  import sys
  
  class ImportUrllibTest(unittest.TestCase):
      def test_urllib(self):
-         """
-         This should perhaps fail: importing urllib first means that the import hooks
-         won't be consulted when importing urllib.response.
-         """
          import urllib
-         print(urllib.__file__)
+         orig_file = urllib.__file__
+         from future.standard_library.urllib import response as urllib_response
+         self.assertEqual(orig_file, urllib.__file__)
-         from future import standard_library
-         with standard_library.hooks():
-             import urllib.response
-         print(urllib.__file__)
-         print(urllib.response.__file__)
+         print(urllib_response.__file__)
  
  if __name__ == '__main__':
      unittest.main()
  
Change urllib test to use an explicit import
## Code Before:
from __future__ import absolute_import, print_function

import unittest
import sys

class ImportUrllibTest(unittest.TestCase):
    def test_urllib(self):
        """
        This should perhaps fail: importing urllib first means that the import hooks
        won't be consulted when importing urllib.response.
        """
        import urllib
        print(urllib.__file__)
        from future import standard_library
        with standard_library.hooks():
            import urllib.response
        print(urllib.__file__)
        print(urllib.response.__file__)

if __name__ == '__main__':
    unittest.main()

## Instruction:
Change urllib test to use an explicit import
## Code After:
from __future__ import absolute_import, print_function

import unittest
import sys

class ImportUrllibTest(unittest.TestCase):
    def test_urllib(self):
        import urllib
        orig_file = urllib.__file__
        from future.standard_library.urllib import response as urllib_response
        self.assertEqual(orig_file, urllib.__file__)
        print(urllib_response.__file__)

if __name__ == '__main__':
    unittest.main()
