[requirements][all] migration OFF of mock to the unittest.mock built-in library

Eric Fried openstack at fried.cc
Thu Mar 12 17:37:35 UTC 2020


> I'd like to suggest, now that we are on modern python, that we stop
> using the mock library and instead use the built in mock library.

+1.

I started working on this a few weeks ago for nova, and came to the
conclusion that it's going to be a multi-step process. This is because
step 2 (see below) is going to take a long time and be quite difficult.

1) a) i) Remove mock-the-lib from $project's requirements.
     ii) Make $project explicitly import unittest.mock everywhere:
s/import mock/from unittest import mock/
    iii) Handle any weird fallout.
   You can see i) and ii) for nova here:
https://review.opendev.org/#/c/708262/
   ...but I likely won't get a chance to work on iii), which would need
to happen in the same patch.

   b) Poison the use of `import mock` e.g. via a hacking rule so it
doesn't creep back in. Example in nova:
https://review.opendev.org/#/c/708768/

2) Ferret out and eradicate all transitive dependencies. This is the
hard part. That said, if we do 1) everywhere, maybe we don't need to do
this.

3) Remove mock-the-lib from the requirements repo. We can't reasonably
do this until {every requirements-using repo has done 1)} or {2) has
happened}.

Thanks,
efried
.



More information about the openstack-discuss mailing list