Mocking `from foo import *` functions

Silfheed silfheed at gmail.com
Fri Jan 9 22:21:56 EST 2009


So I'm in the current testing situation:

sender.py:
-------------
def sendEmails():
   return "I send emails"

alerter.py:
-------------
from sender import *
def DoStuffAndSendEmails():
  doStuff()
  sendEmails()

I'm trying to write a test fn that will test DoStuffAndSendEmails()
(as well as it's kin) without actually sending any emails out.  I
could go through alter alerter so that it does `import sender` and
then find and replace fn() with sender.fn() so I can just create a
mock fn fakeSendEmails() and and do something like sender.sendEmails =
fakeSendEmails, but I'd rather not.

Anyone know how to test alerter.py with out altering the file?

Thanks!



More information about the Python-list mailing list