[openstack-dev] [all] [tests] Considering mock alternatives?

Robert Collins robertc at robertcollins.net
Fri Jul 10 11:13:27 UTC 2015


On 10 July 2015 at 23:04, Dmitry Tantsur <dtantsur at redhat.com> wrote:
> Hi all,
>
> Recent breakage makes me finally raise the question that bothered me for
> some time: are there possible alternatives to mock library we could use?

There are. Personally, mock is probably about equal evil-wise to any
mocking library - I find mocking leads to a very heavy dependence on
large functional test suites. But thats a different discussion.

> A couple reasons for that:
>
> 1. Devs don't seem to care about semver, backward compatibility and all this
> boring stuff. Releasing a minor version that breaks all or vast majority of
> users is not nice at all.

Fortunately thats not what happened. Openstack had a lot of tests that
were broken, mock 1.1.0 held up a mirror and let us see that. Its the
same mock thats in the standard library - unittest.mock - backported;
any use of unittest.mock from Python 3.5 would have shown the same
thing. There are no breaks to the actual API as far as I can tell[1].

> 2. side_effect syntax is no longer sane. Previously it was awesome:
>
>  side_effect = Exception()
>  side_effect = [value, Exception()]
>
> etc. Now it's a big typing disaster:
>
>  side_effect = iter([Exception()])
>
> ok, I can live with [], I understand that it may be required for some corner
> cases. I can't understand why mock can't call iter() internally.
> And seriously, it's a breaking change, and should have been
> communicated/issued a warning for some time.

It doesn't show up in the test suite - and I put specific code in
place to deal with the potentially related case where Python 2.7's
next() is different to the 3.x next() [2.6 didn't have next()]. So -
if you've found something that works in unittest.most on Python 3.6
[or 3.5beta3] then its a genuine backport bug and I can fix that up
asap. I haven't seen a bug filed from you about it, so perhaps thats
the first step.

> If someone has contacts within mock team, are there any chances that will
> provide a convenient alternative to side_effect (though any new attribute
> would be a breaking change for Mock class)?

Any new features should be discussed in either the Python bug tracker
(bugs.python.org) or the python-ideas mailing list. But first lets
make sure this isn't just a bug in the backports.

> Any ideas?
> Dmitry.

[1]: There is one under investigation from Neutron, but it certainly
wasn't a known issue, and the fairly extensive test suite doesn't show
it.

-Rob


-- 
Robert Collins <rbtcollins at hp.com>
Distinguished Technologist
HP Converged Cloud



More information about the OpenStack-dev mailing list