Replace mocked_function.called_with() with mocked_function.assert_called_with()

Bug #2007276 reported by Corey Bryant
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Cinder Charm
Confirmed
Undecided
Trent Lloyd
OpenStack Keystone Charm
Confirmed
Undecided
Unassigned

Bug Description

Before mock v5, if you mock something, you can call any random function on it, and it just does nothing.

A common mistake is thus, to call mocked_function.called_with(param), it should have been:
mocked_function.assert_called_with(param)

It doesn't error, as it just makes a mock call to 'called_with' but it doesn't actually test the assertion.

In mock v5 from pypi they added some code to catch that common mistake and error out.

Thank you to Trent Lloyd for the above details and pointing this out.

Revision history for this message
Trent Lloyd (lathiat) wrote (last edit ):

Examples:

charm-cinder:
https://review.opendev.org/c/openstack/charm-cinder/+/871677

charm-keystone:
https://openstack-ci-reports.ubuntu.com/artifacts/e7c/870345/1/check/tox-py38/e7c9db2/job-output.txt

Applies to multiple methods not just called_with, e.g. keystone hits it on:
called_once
called_with
has_calls

Changed in charm-cinder:
assignee: nobody → Trent Lloyd (lathiat)
status: New → Confirmed
Changed in charm-keystone:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.