derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

patch decorator applied to test case should patch setUp too. #166

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
1. Build a relatively complex test case
2. Use patch decorators to mock/stub/patch out dependancies for all tests
3. Refactor repeating code in setUp
4. Run the test - and it will fail (or do stuff for real)

It would be useful it setUp was decorated as every method prefixed with 
TEST_PREFIX is. 

Original issue reported on code.google.com by orionrobots on 8 Aug 2012 at 11:06

GoogleCodeExporter commented 9 years ago
So this is when using patch as a class decorator?

This would be backwards incompatible to do it all automatically - but it could 
be enabled with a flag.

You can achieve the same effect currently but doing the patching in the setUp - 
calling patch.start() to put the patches in place and patch.stopall() in the 
tearDown

Original comment by fuzzyman on 8 Aug 2012 at 11:08

GoogleCodeExporter commented 9 years ago
That was the idea. Can patch.start be called on all patches - or must it be 
called once per patch (if I have 3 or 4)? 
I cannot find the stopAll method in the documentation 
(http://www.voidspace.org.uk/python/mock/). 

Original comment by orionrobots on 10 Aug 2012 at 8:08

GoogleCodeExporter commented 9 years ago
stopall is new in 1.0 (still in beta). The docs are at:
http://mock.readthedocs.org/en/latest/index.html

For mock 0.8 you'll need to use patch.stop individually on patchers. There is 
no patch.startall because patch.start returns the mock created by the patcher - 
so generally you'll want to keep a reference to the return value.

Original comment by fuzzyman on 10 Aug 2012 at 2:24