Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

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
>>> 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
>>> m.assert_called_once()
>>> m.assert_called()
>>> m.assert_has_calls([call()])

nosy: +xtreak

Python tracker <rep...@bugs.python.org>
Python-bugs-list mailing list

Reply via email to