Skip to content

Commit

Permalink
Fix missing assert_ prefix on called_with
Browse files Browse the repository at this point in the history
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 (python/cpython#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
  • Loading branch information
lathiat committed Feb 16, 2023
1 parent d6186f3 commit 79bbb2b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion unit_tests/test_cinder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def test_clean_storage_unmount(self):
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'
Expand Down

0 comments on commit 79bbb2b

Please sign in to comment.