Skip to content

Commit

Permalink
tests: image: fix incorrect assertion test
Browse files Browse the repository at this point in the history
Python v3.12 and later raise an exception for this line with the
following message:
"""
AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?
"""

A bit of research returned commit 1d4d677d1c90 ("gh-100690: Raise an
AttributeError when the assert_ prefix is forgotten when using Mock
(#100691)") from CPython git history, which in turns points at
python/cpython#100690.

This GitHub issue mentions that called_once_with returns a Mock object
instead of doing a proper assertion. This test is basically a no-op.

Therefore, let's fix the test by doing a proper assertion.

Fixes: 94d64c8 ("test: image: improve code coverage by testing BaseImage")
Signed-off-by: Quentin Schulz <[email protected]>
  • Loading branch information
QSchulz committed Dec 30, 2023
1 parent 01e6296 commit b6b0753
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_copy_filepath_remove_superficial_options(
):
base = BaseImage({"name": "test.jpg", "resize": "50%", "test": "test123"}, {})
copy = base.copy()
mock_rm_sup_opt.called_once_with(
mock_rm_sup_opt.assert_called_once_with(
{"name": "test.jpg", "resize": "50%", "test": "test123"}
)
assert copy == "test-%s-100x150.jpg" % (
Expand Down

0 comments on commit b6b0753

Please sign in to comment.