New submission from Daniel Watkins: The convenience assertion methods on mock objects can be easily mistyped and if they are mistyped, they will silently pass. This can be quite user-hostile. Consider the following:
>>> example = Mock() >>> example.assert_called_once() >>> example.assert_caled_once_with(...) This will not raise any exceptions, though the first feels natural and the latter is misspelt. To avoid using the methods, one can type: >>> example = Mock() >>> assert example.call_count == 1 >>> assert example.call_args_list == [call(...)] but the meaning of that latter statement is particularly non-obvious. Instead, it would be great if I could import the assertions from mock as functions, and call them with mock as the first argument: >>> from unittest.mock import assert_called_once # This will be an ImportError >>> example = Mock() >>> assert_caled_once_with(example, ...) # A NameError >>> assert_called_once_with(example, ...) # Great success! ---------- components: Tests messages: 298533 nosy: odd_bloke priority: normal severity: normal status: open title: Provide assertion functions in unittest.mock versions: Python 3.7 _______________________________________ Python tracker <[email protected]> <http://bugs.python.org/issue30949> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
