[TIP] Struggling with pymock

Tobias Roth misc.lists at fsck.ch
Mon Sep 10 23:38:07 PDT 2007

> I'd suggest not doing this at all though, and instead parameterizing the
> open function somehow, so that your tests can supply the mock directly
> to the code being tested, intead of overriding it for the entire process.

Thanks Jean-Paul. I moved away from stubbing out __builtins__.open()
directly, and nosetest works nicely again.

Now there's only one (I hope) problem left, I repeat it here for people
not having to read the whole thread again:

** repetition **
1) The output [of pymock] is very unclear. I often get a 'raise
further actions defined"', with no chance of finding out what went
wrong. Consider the following example:

s = open("file")
for line in s:

For the open() and close() alone, I was able to get the test running as
you suggested, by stubbing out __builtins__.open(). But when I add some
reading, I always get the "No further actions defined". How do I find
out what methods to record here? More detailed output from pymock would
really help, especially when overriding stuff from libraries.
** end repetition **

It's making more sense with every reply I get, so keep them coming :-)


More information about the testing-in-python mailing list