[openstack-dev] [all] [tests] Considering mock alternatives?
dtantsur at redhat.com
Fri Jul 10 11:34:56 UTC 2015
On 07/10/2015 01:13 PM, Robert Collins wrote:
> 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.
I see that a lot of code started breaking due to
side_effect = Exception()
no longer working. Which was a declared way for some time, at least to
my best knowledge. And I do realize it's just a back port, but as a user
of a _library_ I'd like such breakages to be treated with care.
Maybe it happened and I was just not looking at a proper place.
>> 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.
People say it's stopped working in Python 3.4.2 and it did work in
Python 3.4.0. I didn't verify this sentence.
>> 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?
> : There is one under investigation from Neutron, but it certainly
> wasn't a known issue, and the fairly extensive test suite doesn't show
More information about the OpenStack-dev