hRobert12 / mock

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

Provide a way to customize the class of child mocks without needing to implement _get_child_mock #167

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Attached is a patch implementing an arg to __init__ for all mocks that the 
default _get_child_mock implementation can use to instantiate child mocks. This 
can be used, for example, when subclassing, if different configuration needs to 
be done on a parent mock than on child mocks. See the doc changes for a 
concrete example.

(Tests pass for me on tip under all interpreters I have installed, which are 
all but py24, py31 and jython).

Cheers.

Original issue reported on code.google.com by jul...@grayvines.com on 8 Aug 2012 at 6:52

Attachments:

GoogleCodeExporter commented 8 years ago
So overriding _get_child_mock is the intended (and documented) way of doing 
this, but your way is easier - at the cost of a new keyword argument to the 
already-has-too-many-arguments Mock constructor.

This would have to be in mock 1.1, which would be released at the same time as 
Python 3.4 (although there will be early alphas).

Original comment by fuzzyman on 5 Nov 2012 at 9:17

GoogleCodeExporter commented 8 years ago
Attaching the original example for some context for where this came up:

http://bpaste.net/show/56061/

Original comment by Jul...@GrayVines.com on 5 Nov 2012 at 9:22