[cinder] Unit test failures under Python 3.11 - mocks can no longer be provided as the specs for other Mocks
Hi, Since python3.11 mocks can no longer be provided as the specs for other Mocks. As a result, an already-mocked object cannot be passed to mock.Mock(). This can uncover bugs in tests since these Mock-derived Mocks will always pass certain tests (e.g. isinstance) and built-in assert functions (e.g. assert_called_once_with) will unconditionally pass.[1] There's a bug report to track this issue in Cinder [2] but I think this may affect other projects too. I've reproduce the error and most drivers fail with: ``` unittest.mock.InvalidSpecError: Cannot spec a Mock object. [object=<Mock name='mock.client.HPE3ParClient' id='139657768087760'>] ``` Cheers, Sofia [1] https://github.com/python/cpython/issues/87644 [2] https://bugs.launchpad.net/cinder/+bug/2000436 -- Sofía Enriquez she/her Software Engineer Red Hat PnT <https://www.redhat.com> IRC: @enriquetaso @RedHat <https://twitter.com/redhat> Red Hat <https://www.linkedin.com/company/red-hat> Red Hat <https://www.facebook.com/RedHatInc> <https://www.redhat.com>
This is a good catch. We should get a hold of this before it creeps on us in CI. Maybe we should open it in shared backlog? On Wed, Jan 4, 2023 at 11:00 AM Sofia Enriquez <senrique@redhat.com> wrote:
Hi,
Since python3.11 mocks can no longer be provided as the specs for other Mocks. As a result, an already-mocked object cannot be passed to mock.Mock(). This can uncover bugs in tests since these Mock-derived Mocks will always pass certain tests (e.g. isinstance) and built-in assert functions (e.g. assert_called_once_with) will unconditionally pass.[1]
There's a bug report to track this issue in Cinder [2] but I think this may affect other projects too.
I've reproduce the error and most drivers fail with: ``` unittest.mock.InvalidSpecError: Cannot spec a Mock object. [object=<Mock name='mock.client.HPE3ParClient' id='139657768087760'>] ```
Cheers, Sofia
[1] https://github.com/python/cpython/issues/87644 [2] https://bugs.launchpad.net/cinder/+bug/2000436 --
Sofía Enriquez
she/her
Software Engineer
Red Hat PnT <https://www.redhat.com>
IRC: @enriquetaso @RedHat <https://twitter.com/redhat> Red Hat <https://www.linkedin.com/company/red-hat> Red Hat <https://www.facebook.com/RedHatInc> <https://www.redhat.com>
On 1/4/23 11:36, Jiri Podivin wrote:
This is a good catch. We should get a hold of this before it creeps on us in CI. Maybe we should open it in shared backlog?
As much as I know, only Cinder has this bug (I know because all of Debian OpenStack package are running unit tests at build time, and all of them were rebuilt with Python 3.11 recently). Please help finish this: https://review.opendev.org/c/openstack/cinder/+/869396 Also, I need help fixing this one: https://bugs.debian.org/1026524 which I didn't forward upstream yet, but someone on IRC worked on it (can't remember who...). Cheers, Thomas Goirand (zigo)
On Wed, Jan 4 2023 at 09:26:10 AM +00:00:00, Sofia Enriquez <senrique@redhat.com> wrote:
Hi,
Since python3.11 mocks can no longer be provided as the specs for other Mocks. As a result, an already-mocked object cannot be passed to mock.Mock(). This can uncover bugs in tests since these Mock-derived Mocks will always pass certain tests (e.g. isinstance) and built-in assert functions (e.g. assert_called_once_with) will unconditionally pass.[1]
There's a bug report to track this issue in Cinder [2] but I think this may affect other projects too.
I've reproduce the error and most drivers fail with: ``` unittest.mock.InvalidSpecError: Cannot spec a Mock object. [object=<Mock name='mock.client.HPE3ParClient' id='139657768087760'>] ```
Nova went through this and removed double mocking during Zed. Here are the patches: https://review.opendev.org/q/topic:unittest.mock+%2522double+mocking%2522 Maybe you can use it for ideas how to deal with different double mocking scenarios: Cheers, gibi
Cheers, Sofia
[1] <https://github.com/python/cpython/issues/87644> [2] <https://bugs.launchpad.net/cinder/+bug/2000436> -- Sofía Enriquez
she/her
Software Engineer
Red Hat PnT <https://www.redhat.com/>
IRC: @enriquetaso
@RedHat <https://twitter.com/redhat> Red Hat <https://www.linkedin.com/company/red-hat> Red Hat <https://www.facebook.com/RedHatInc> <https://www.redhat.com/>
participants (4)
-
Balazs Gibizer
-
Jiri Podivin
-
Sofia Enriquez
-
Thomas Goirand