How to force an ImportError on development machine? (pwd module)

google-app-engine, import, pwd, python, ubuntu

Solution

Even easier than messing with `__import__` is just inserting `None` in the sys.modules dict:

>>> import sys
>>> sys.modules['pwd'] = None
>>> import pwd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pwd

Problem

I'm trying to use a third-party lib (docutils) on Google App Engine and have a problem with this code (in docutils): ``` try: import pwd do stuff except ImportError: do other stuff ``` I want the import to fail, as it will on the actual GAE server, but the problem is that it doesn't fail on my development box (ubuntu). How to make it fail, given that the import is not in my own code?

Original source

Related problems