[cinder] Unit test failures under Python 3.11 - mocks can no longer be provided as the specs for other Mocks

Sofia Enriquez senrique at redhat.com
Wed Jan 4 09:26:10 UTC 2023


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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.openstack.org/pipermail/openstack-discuss/attachments/20230104/24094c5c/attachment.htm>


More information about the openstack-discuss mailing list