[TIP] Problem with mock
julian at grayvines.com
Thu Dec 20 07:01:21 PST 2012
I can't elaborate much from here, but your issue is due to not replacing
super in the correct spot, so your mom isn't being injected properly.
You need to replace in the module under test (can't link to the docs but
there's a helpful article there if you can't figure it out).
with mock.patch("mymodule.super", create=True) as mock_super:
mock_super.return_value.config.whatever = 12
Remembering your code from memory and typing off the cuff, but hopefully
this puts you on your way, otherwise I'm sure someone else can pick it up
from here. Also note the need for create.
Also, doing this is messy. You should give some thought into rethinking
your design. Specifically, separating child from superclass is smelly,
maybe the child ought not be a child at all (and maybe it should compose
with the super).
Anyways, good luck
On Dec 20, 2012 9:49 AM, "Ken Hagler" <khagler at orange-road.com> wrote:
> On Dec 19, 2012, at 2:57 PM, John Wong <gokoproject at gmail.com> wrote:
> > I usually mock a class by using autospec parameter so the specs of the
> > class remains except it's MOCKed.
> > That allows me to just quickly mock out the class I want while keeping
> > the necessary attributes/method I need.
> Reasonable, but would I use Build or DevBuild for that? I suppose I'm wary
> of adding another factor that I don't particularly understand when it's
> already not working...
> > Also, the error doesn't indicate it's a mock object. If it were a mock, I
> > believe you would see "MagicMock object" rather than DevBuild object.
> Okay, any idea what I'm doing wrong there?
> Ken Hagler
> | http://www.orange-road.com/ |
> | And tho' we are not now that strength which in old days |
> | Moved earth and heaven, that which we are, we are --Tennyson |
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python