old_contents: """
  Test what happens if Python was built without SSL
  
  * Everything that does not involve HTTPS should still work
  * HTTPS requests must fail with an error that points at the ssl module
  
  NOTE:
  
      This file is intentionally named to be sorted *last*.
      We mess with the import machinery which breaks mock, so we want to run
      after mock has done its stuff
  """
  
  import sys
  import unittest
  
  
  class ImportBlocker(object):
      """
      Block Imports
  
      To be placed on ``sys.meta_path``. This ensures that the modules
      specified cannot be imported, even if they are a builtin.
      """
      def __init__(self, *namestoblock):
          self.namestoblock = namestoblock
  
      def find_module(self, fullname, path=None):
          if fullname in self.namestoblock:
              return self
          return None
  
      def load_module(self, fullname):
          raise ImportError('import of {0} is blocked'.format(fullname))
  
  
  ssl_blocker = ImportBlocker('ssl', '_ssl')
  
  
  class TestWithoutSSL(unittest.TestCase):
  
      @classmethod
      def setUpClass(cls):
          sys.modules.pop('ssl', None)
          sys.modules.pop('_ssl', None)
  
          sys.modules.pop('urllib3', None)
  
          for module in list(sys.modules.keys()):
              if module.startswith('urllib3.'):
                  sys.modules.pop(module)
  
          sys.meta_path.insert(0, ssl_blocker)
  
      @classmethod
      def tearDownClass(cls):
          assert sys.meta_path.pop(0) == ssl_blocker
  
      def test_cannot_import_ssl(self):
          # python26 has neither contextmanagers (for assertRaises) nor
          # importlib.
          # 'import' inside 'lambda' is invalid syntax.
          def import_ssl():
              import ssl
  
          self.assertRaises(ImportError, import_ssl)
  
      def test_import_urllib3(self):
          import urllib3
  
new_contents: """
  Test what happens if Python was built without SSL
  
  * Everything that does not involve HTTPS should still work
  * HTTPS requests must fail with an error that points at the ssl module
  
  NOTE:
  
      This file is intentionally named to be sorted *last*.
      We mess with the import machinery which breaks mock, so we want to run
      after mock has done its stuff
  """
  
  import sys
  import unittest
  
  
  class ImportBlocker(object):
      """
      Block Imports
  
      To be placed on ``sys.meta_path``. This ensures that the modules
      specified cannot be imported, even if they are a builtin.
      """
      def __init__(self, *namestoblock):
          self.namestoblock = namestoblock
  
      def find_module(self, fullname, path=None):
          if fullname in self.namestoblock:
              return self
          return None
  
      def load_module(self, fullname):
          raise ImportError('import of {0} is blocked'.format(fullname))
  
  
  class ModuleStash(object):
      """
      Stashes avail previously imported modules
  
      If we reimport a module the data from coverage is lost, so we reuse the old
      modules
      """
  
      def __init__(self, namespace, modules=sys.modules):
          self.namespace = namespace
          self.modules = modules
          self._data = {}
  
      def stash(self):
          self._data[self.namespace] = self.modules.pop(self.namespace, None)
  
          for module in list(self.modules.keys()):
              if module.startswith(self.namespace + '.'):
                  self._data[module] = self.modules.pop(module)
  
      def pop(self):
          for module in list(self.modules.keys()):
              if module.startswith(self.namespace + '.'):
                  self.modules.pop(module)
  
          self.modules.update(self._data)
  
  
  ssl_blocker = ImportBlocker('ssl', '_ssl')
  module_stash = ModuleStash('urllib3')
  
  
  class TestWithoutSSL(unittest.TestCase):
  
      @classmethod
      def setUpClass(cls):
          sys.modules.pop('ssl', None)
          sys.modules.pop('_ssl', None)
  
          module_stash.stash()
          sys.meta_path.insert(0, ssl_blocker)
  
      @classmethod
      def tearDownClass(cls):
          assert sys.meta_path.pop(0) == ssl_blocker
          module_stash.pop()
  
      def test_cannot_import_ssl(self):
          # python26 has neither contextmanagers (for assertRaises) nor
          # importlib.
          # 'import' inside 'lambda' is invalid syntax.
          def import_ssl():
              import ssl
  
          self.assertRaises(ImportError, import_ssl)
  
      def test_import_urllib3(self):
          import urllib3
  
subject: use a module stash to not trip up coverage