Here's one of many things I've learnt today at PyCon. Inspired by code that Grig Gheorghiu showed in his slides on automated testing, you can monkey patch a standard library that your application is using in your unit tests to, in my case, mock a remote service without having to run a server. I've done lots of monkey-patching in Zope but then I've only been monkey patching individual methods or attributes of imported classes. This is very similar to that. Here's what my application does:
from poplib import POP3
class MyZopeApp(...):
def check4mail(self, hostname, port, user, pwd):
connection = POP3(hostname, port=port)
...download emails and process them...
Adjacent to this I have a unit/integration test that looks like this:
class TestCase(ZopeTestCase):
def test_check4mail(self):
# monkey patch!
# note that this imports a module, not a class
from Products.IssueTrackerProduct import IssueTracker
FakePOP3.files = ('test1.email',)
IssueTracker.POP3 = FakePOP3
# now check what happens when check4mail() is run
result = self.folder.tracker.check4mail()
assert ...