[TIP] Using CaptureMock for calls that return objects

Kumar McMillan kumar.mcmillan at gmail.com
Wed Apr 6 15:37:15 PDT 2011


Hi Geoff and all,
I've been curious to see if CaptureMock [1] can speed up my test
suite's database access by recording the calls after fixture data has
loaded then replaying the calls using the captured results.  The issue
I'm running into is that CaptureMock does not seem to handle calls
that return objects (as opposed to native types).  Before I post some
tracebacks has someone already done something similar to this with
CaptureMock?

To give a specific example, I am trying to capture/replay a Django
manager, something like MyModel.objects.all().  The return value of
all() is an iterable of MyModel() instances that I'd like to get
replayed from a cached file.  They don't have to be actual instances,
just things that can be used like object.name, object.foo.

[1] http://texttest.carmen.se/index.php?page=capturemock



More information about the testing-in-python mailing list