[issue47209] Documentation for asserting values of `unittest.mock.Mock.call_args_list`

2022-04-03 Thread himkt


himkt  added the comment:

> It only need to wrap an argument when it is a singular value.

It is also wrong..., sorry.
To compare a single value, I should have passed a tuple of tuples.

```
> python demo.py
>   
>2022-04-04 14:56:41
mock_obj.call_args_list
[call(1), call(2)]
mock_obj.call_args_list == [(1,), (2,)]
False
mock_obj.call_args_list == [call(1,), call(2,)]
True
mock_obj.call_args_list == [((1,),), ((2,),)]
True
```

--

___
Python tracker 
<https://bugs.python.org/issue47209>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47209] Documentation for asserting values of `unittest.mock.Mock.call_args_list`

2022-04-03 Thread himkt


himkt  added the comment:

So sorry, documentation is not wrong.
It only need to wrap an argument when it is a singular value.

But I'm still wondering if we can unify documentation to wrap `call` (e.g. 
https://github.com/himkt/cpython/blob/main/Doc/library/unittest.mock-examples.rst#checking-multiple-calls-with-mock
 does it).

--

___
Python tracker 
<https://bugs.python.org/issue47209>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47209] Documentation for asserting values of `unittest.mock.Mock.call_args_list`

2022-04-03 Thread himkt


New submission from himkt :

Currently documentation says we can check call_args_list by providing a list of 
tuples of arguments.

```
>>> expected = [(), ((3, 4),), ({'key': 'fish', 'next': 'w00t!'},)]
>>> mock.call_args_list == expected
True
```

(from 
https://docs.python.org/3.11/library/unittest.mock.html#unittest.mock.Mock.call_args_list)

However, I think we have to wrap all arguments with `call`.
I'd happy to send a patch if it should be fixed.


### Reproduce:

```
import time
from unittest.mock import call
from unittest.mock import patch


with patch("time.sleep") as mock_obj:
time.sleep(1)
time.sleep(2)

print("mock_obj.call_args_list")
print(mock_obj.call_args_list)

print("mock_obj.call_args_list == [(1,), (2,)]")
print(mock_obj.call_args_list == [(1,), (2,)])
print("mock_obj.call_args_list == [call(1,), call(2,)]")
print(mock_obj.call_args_list == [call(1,), call(2,)])
```

```
> python demo.py
>   
>2022-04-04 12:03:18
mock_obj.call_args_list
[call(1), call(2)]
mock_obj.call_args_list == [(1,), (2,)]
False
mock_obj.call_args_list == [call(1,), call(2,)]
True
```


### Links

- Documentation in repo: 
https://github.com/python/cpython/blob/4216dce04b7d3f329beaaafc82a77c4ac6cf4d57/Doc/library/unittest.mock.rst
- Documentation in page: 
https://docs.python.org/3.11/library/unittest.mock.html#unittest.mock.Mock.call_args_list

--
assignee: docs@python
components: Documentation
messages: 416650
nosy: docs@python, himkt
priority: normal
severity: normal
status: open
title: Documentation for asserting values of `unittest.mock.Mock.call_args_list`
type: behavior
versions: Python 3.11

___
Python tracker 
<https://bugs.python.org/issue47209>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com