Message356353
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()]) |
|
Date |
User |
Action |
Args |
2019-11-11 04:36:22 | xtreak | set | recipients:
+ xtreak, piscvau |
2019-11-11 04:36:22 | xtreak | set | messageid: <1573446982.28.0.917559355582.issue38763@roundup.psfhosted.org> |
2019-11-11 04:36:22 | xtreak | link | issue38763 messages |
2019-11-11 04:36:21 | xtreak | create | |
|