[TIP] mock and patch

Michael Foord michael at voidspace.org.uk
Thu Mar 22 07:48:36 PDT 2012

On 22/03/2012 14:46, Andrea Crotti wrote:
> On 03/22/2012 02:42 PM, Michael Foord wrote:
>> The error is not from a mock, but from your actual walk function - 
>> which indicates that the patching is not in place. So it's likely 
>> that the patch is in the wrong place. It looks like you're patching 
>> the walk function in the walk module - but using it somewhere else. 
>> So changing your patch to "module_importing_and_using_walk.walk" 
>> instead should work.
>> All the best,
>> Michael
> Actually I discovered a funny thing, I got this error by running
> nosetests -m regexp
> but running nosetest only I didn't, with exactly the same code.
> So if I can reproduce it it might be a small bug in nose, or is it 
> normal to get a different behaviour
> when running only one test??
Odd. That *sounds* like a bug in nose. One possibility is that the 
module path is different when running all the tests and a single test, 
so the patching is working when you run all tests and not when you run 
one. If you "print __name__" at the module level (where walk lives) 
you'll be able to see if they are different when you run the tests 
different ways.



May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html

More information about the testing-in-python mailing list