Fix missing assert_ prefix on called_with

test_clean_storage_unmount incorrectly used 'called_with' instead of
'assert_called_with' which just made a mock function call and didn't
check or assert that the function was actually called.

As a result this function didn't actually test anything, the expected
parameters were not correct so they have been updated.

An error to catch this accidental mistake was added in the recently
released mock 5.0.1 (https://github.com/python/cpython/issues/100690)
  AttributeError: 'called_with' is not a valid assertion.
  Use a spec for the mock if 'called_with' is meant to be an attribute.

The mock library ships in python as unittest.mock but also publishes the
latest code as the 'mock' python package so that older python versions
can get the latest code. The stable branches currently install mock
but the master branch does not, so this error does not actually appear
on master but only the <=yoga stable branches currently. The test is
however wrong either way.

Change-Id: I3076778e8fc62c086651d29abb2c5a3d9921be97
This commit is contained in:
Trent Lloyd 2023-01-25 11:55:32 +08:00
parent ba8d8fc3e1
commit ceafd9f67f

View File

@ -405,7 +405,7 @@ class TestCinderUtils(CharmTestCase):
self.zap_disk.return_value = True
self.mounts.return_value = MOUNTS
cinder_utils.clean_storage('/dev/fakevbd')
self.umount.called_with('/dev/fakevbd', True)
self.umount.assert_called_with('/mnt', persist=True)
def test_clean_storage_lvm_wipe(self):
'It removes traces of LVM when cleaning storage'