Navigation: home >capturemock>filtering
Capture-Replay Mocking with CaptureMock
Filtering what is recorded
Repeated calls
Ordinarily, CaptureMock will record every call made to an intercepted function. This can be important, as some functions will return different results when called subsequently. For some things though, it just creates clutter, and then it's useful to be able to disable it.
For example, suppose we want to test locale-specific behaviour. The easiest way to do that is to intercept locale.getdefaultlocale, but the value of this is very unlikely to change during the run. So we configure as follows:
intercepts = locale.getdefaultlocale

check_repeated_calls = False
This will then result in a mock file that neatly says something like
->RET:('en_US', 'UTF8')
instead of the same information repeated lots of times for every time we call this method.
You can also disable it "across the board", i.e. in the general Python section, like this:
intercepts = locale.getdefaultlocale,something.else,
check_repeated_calls = False
Callstack filtering
If you intercept something quite low-level, such as "os.getpid" you run into the issue that this may well be called by the standard library itself, or by development tools like StoryText or This obviously leads to far more calls being intercepted and recorded than you actually want.
CaptureMock therefore makes sure that any calls made by the standard library or by its own interceptor programs are not intercepted and recorded. This does mean that you need to intercept exactly the right thing. For example it will not work to intercept "subprocess.Popen" if your program actually calls "", even though the latter calls the former internally.
To tell it to block calls made from other places, you would do as follows.
intercepts = os.getpid
ignore_callers = coverage,usecase
This will intercept "os.getpid" except when it is called from any module in a directory called "coverage" or from the "usecase" module, assuming our tests might use StoryText and to extract information.

Last updated: 05 October 2012