This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Caris Moses
Recipients Caris Moses, Claudiu.Popa, and, cjw296, iforapsy, kushal.das, mariocj89, michael.foord, xtreak
Date 2019-10-16.20:16:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571256981.74.0.751006853116.issue21478@roundup.psfhosted.org>
In-reply-to
Content
I believe I have found another bug related to this issue. I can start a new issue if necessary. When I use some_mock.attach_mock(...) and make calls, the resulting some_mock.call_args is None while the some_mock.mock_calls list is not empty.

The code below shows this in Python 3.7.5:

from unittest import TestCase
from unittest.mock import patch, Mock

def foo(value):
    return value

class MyObjectTest(TestCase):

    @patch(f'{__name__}.foo')
    def test_do_something(self, mock_foo):
        manager = Mock()
        manager.attach_mock(mock_foo, 'foo_func')
        foo(3)
        print(manager.mock_calls)
        print(manager.call_args)

if __name__ == "__main__":
    unittest.main()

The print statements return:
[call.foo_func(3)]
None

While the code below (without attach_mock) works fine:
from unittest import TestCase
from unittest.mock import patch, Mock

def foo(value):
    return value

class MyObjectTest(TestCase):

    @patch(f'{__name__}.foo')
    def test_do_something(self, mock_foo):
        foo(3)
        print(mock_foo.mock_calls)
        print(mock_foo.call_args)

if __name__ == "__main__":
    unittest.main()

Print statements correctly return:
[call(3)]
call(3)

for completeness the call_args_list also returns [] when using attach_mock. I also tested in Python 3.8.0 and got the same result.
History
Date User Action Args
2019-10-16 20:16:21Caris Mosessetrecipients: + Caris Moses, cjw296, michael.foord, Claudiu.Popa, kushal.das, and, mariocj89, xtreak, iforapsy
2019-10-16 20:16:21Caris Mosessetmessageid: <1571256981.74.0.751006853116.issue21478@roundup.psfhosted.org>
2019-10-16 20:16:21Caris Moseslinkissue21478 messages
2019-10-16 20:16:21Caris Mosescreate