[openstack-dev] [nova] Do we have some guidelines for mock, stub, mox when writing unit test?

Ben Nemec openstack at nemebean.com
Mon Dec 23 16:45:08 UTC 2013


On 2013-12-21 07:24, Matt Riedemann wrote:
> On 12/19/2013 8:51 AM, John Garbutt wrote:
>> On 4 December 2013 17:10, Russell Bryant <rbryant at redhat.com> wrote:
>>> I think option 3 makes the most sense here (pending anyone saying we
>>> should run away screaming from mox3 for some reason).  It's actually
>>> what I had been assuming since this thread a while back.
>>> 
>>> This means that we don't need to *require* that tests get converted 
>>> if
>>> you're changing one.  It just gets you bonus imaginary internet 
>>> points.
>>> 
>>> Requiring mock for new tests seems fine.  We can grant exceptions in
>>> specific cases if necessary.  In general, we should be using mock for
>>> new tests.
>> 
>> I have lost track a bit here.
>> 
>> The above seems like a sane approach. Do we all agree on that now?
>> 
>> Can we add the above text into here:
>> https://wiki.openstack.org/wiki/ReviewChecklist#Nova_Review_Checklist
>> 
>> John
>> 
>> _______________________________________________
>> OpenStack-dev mailing list
>> OpenStack-dev at lists.openstack.org
>> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>> 
> 
> Yeah, at some point I wanted to cleanup the various testing guides but
> until then I like the idea of just putting something simple into the
> nova review checklist. Basically use mock for new tests, mox can be
> used in exceptional cases. What I've considered exceptional so far
> includes changes that will be backported to a stable release where
> mock isn't being used and cases where you basically have to bend over
> backwards to work new mock tests into an existing test class that has
> lots of existing setUp with mox. However, even in the latter case you
> can usually use mock after resetting the mox setup via
> self.mox.ResetAll() in the new test case(s).

I went ahead and added this to the wiki, so it's now an absolutely 
inviolate policy.  Unless, ya know, someone edits the wiki after me. ;-)

Also, I put it in the common section because this doesn't seem like 
something we should be doing differently per-project.  If anyone 
objects, feel free to add to the discussion here as to why.

Thanks.

-Ben



More information about the OpenStack-dev mailing list