-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Open
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
When accessing a non-existent assertion method on a [Mock] object( e.g., assert_called_twice_with), the raised [AttributeError] message contains a double period (..) before the "Did you mean" suggestion.
Example
import unittest.mock as mock
m = mock.Mock()
m.assert_called_twice_with(1, 2)
Output
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.12/unittest/mock.py", line 665, in __getattr__
raise AttributeError(
AttributeError: 'assert_called_twice_with' is not a valid assertion. Use a spec for the mock if 'assert_called_twice_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?
Problem
Note the double period ([attribute.. Did you mean] in the error message.
Expected Behavior
The error message should contain only a single period before the suggestion, e.g.:
Expected Output
AttributeError: 'assert_called_twice_with' is not a valid assertion. Use a spec for the mock if 'assert_called_twice_with' is meant to be an attribute. Did you mean: 'assert_called_once_with'?
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PR
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error