cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Inappropriateness in unittest documentation with actual behavior

Open AliyevH opened this issue 1 year ago • 0 comments

Documentation

https://docs.python.org/3/library/unittest.mock.html#auto-speccing https://github.com/python/cpython/blob/c444362c6e0b6c01f49c3bee864100f52bd3b640/Doc/library/unittest.mock.rst#L2615

mock = Mock(name='Thing', return_value=None) mock(1, 2, 3) mock.assret_called_once_with(4, 5, 6) # Intentional typo!

Your tests can pass silently and incorrectly because of the typo.


Expected that tests will pass as written in doc.

But actually script fails with raising error.

raise AttributeError(
AttributeError: 'assret_called_once_with' is not a valid assertion. Use a spec for the mock if 'assret_called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

Am i missing something? I have tested this in Python3.11 and Python 3.12. Looks like documentation must be updated or script must work as said in documenation.

Thanks for attention

AliyevH avatar May 10 '24 14:05 AliyevH