This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients piscvau, xtreak
Date 2019-11-11.04:36:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1573446982.28.0.917559355582.issue38763@roundup.psfhosted.org>
In-reply-to
Content
assert_called_once is supposed to raise an AssertionError if the mock is not called and to return None like other assert_* helpers. The return value is not supposed to be used and it's more of an assertion action where if it's None then it's implied to be True.

>>> from unittest.mock import Mock
>>> def side_effect(*args, **kwargs): print("side_effect called")
...
>>> m = Mock(side_effect=side_effect)
>>> m.call_count
0
>>> m.assert_called_once()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kasingar/stuff/python/cpython/Lib/unittest/mock.py", line 881, in assert_called_once
    raise AssertionError(msg)
AssertionError: Expected 'mock' to have been called once. Called 0 times.
>>> m()
side_effect called
>>> m.call_count
1
>>> m.assert_called_once()
>>> m.assert_called()
>>> m.assert_has_calls([call()])
History
Date User Action Args
2019-11-11 04:36:22xtreaksetrecipients: + xtreak, piscvau
2019-11-11 04:36:22xtreaksetmessageid: <1573446982.28.0.917559355582.issue38763@roundup.psfhosted.org>
2019-11-11 04:36:22xtreaklinkissue38763 messages
2019-11-11 04:36:21xtreakcreate