[TIP] newbie - verifying the type of a basic property set
cmedcoff at hotmail.com
Mon Jul 8 11:09:04 PDT 2013
> If you are simply setting self.bar to the input object, I don't see any
reason to do any mocking. Mocking is useful is you have more than a simple
assignment inside the method. If the logic is simple enough, doing the first
one is enough.
>Is that the template for the real code?
No, this is just a contrived example. My real code is an event handler
method for a gof state machine. It would have code to invoke methods on a
context object in response to an event and then perform a state change on an
attribute of the context which represents its state; hence a test for a
setter to verify that the next state of the state machine is correct based
I just found it a bit clunky that with mock I had to explicitly create the
mock object then assign to its parent. Docs say that accessing a property
will auto-create a mock for the attribute, but doing so doesn't allow me to
perform the kind of test like I wrote in my example.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2422 bytes
Desc: not available
More information about the testing-in-python