Lambda functions are a great tool to stub out functions. They turn out to be much more clear and easy than using a stub from a isolation/test-double framework. Lambda in Python are used like this in interaction-based tests:

class MyTests(unittest.TestCase):
   def test_find_users():
         stub = MyDAO() 
         stub.get_users = lambda: ['carlos', 'juan']
         sut = UserFinder(stub)
         self.assertEquals(
                  sut.get_users_with_name_like('ca'), 
                  ['carlos'])

The method get_users in the class MyDAO is stubbed out as we assign a new function to it. The test gets a much more clear code than using PyMox or other test-doubles framework for stubs.

Moreover Python let us stub out functions from classes that haven’t been instantiated yet, which makes it perfect for interception too. The next example is the way I am using the Google App Engine bulkloader to write integration tests:

from appengine_django import InstallAppengineHelperForDjango
InstallAppengineHelperForDjango()
from google.appengine.tools import bulkloader

def load_data():
     args_dict = {'all the values': 'the bulk loader needs', 
                       'etc': 'etc'}
     bulkloader.RequestManager.AuthFunction = lambda x : ('x', 'y')
     bulkloader.Run(args_dict)

This way the bulkloader runs avoiding the need to manually type in the username and password. RequestManager is a class and AuthFunction is one of its instance members.