Skip to content

Instantly share code, notes, and snippets.

@edc
Created July 30, 2015 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edc/aa2cf49d9662e4034f60 to your computer and use it in GitHub Desktop.
Save edc/aa2cf49d9662e4034f60 to your computer and use it in GitHub Desktop.
How to fail an import in tests
import mock
import sys
class Finder(object):
def find_module(self, name, path=None):
print name, path
raise ImportError
import threading
with mock.patch.object(sys, 'meta_path', [Finder()]):
sys.modules.pop('threading', None)
import threading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment