Mocking ImportError in Python
- by Attila Oláh
I'm trying this for almost two hours now, without any luck.
I have a module that looks like this:
try:
from zope.cpomonent import queryUtility # and things like this
except ImportError:
# do some fallback operations <-- how to test this?
Later in the code:
try:
queryUtility(foo)
except NameError:
# do some fallback actions <-- this one is easy with mocking
# zope.component.queryUtility to raise a NameError
Any ideas?