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 xtreak
Recipients Caris Moses, Claudiu.Popa, and, cjw296, iforapsy, kushal.das, mariocj89, michael.foord, xtreak
Date 2019-10-14.17:40:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571074846.5.0.108200238922.issue21478@roundup.psfhosted.org>
In-reply-to
Content
I tried your example as below using __name__. I received an AttributeError for which issue38473 in 3.7.5RC1 and 3.8.0RC1 and opened issue38473 and I am running my below code under that issue PR. For 3.7.4, I received manager.mock_calls to be an empty list since it doesn't contain the patch for this issue. Can you please confirm my results too.

➜  cpython git:(bpo38473) cat ../backups/bpo21478.py
import unittest
from unittest import TestCase
from unittest.mock import patch, Mock, call, ANY


class MyObject:
    def __init__(self):
        self.foo = 0
        self.bar = 0

    def set_foo(self, value):
        self.foo = value

    def set_bar(self, value):
        self.bar = value


def do_something():
    o = MyObject()
    o.set_foo(3)
    o.set_bar(4)
    return "something unrelated"


class MyObjectTest(TestCase):
    @patch(f"{__name__}.MyObject.set_bar", autospec=True)
    @patch(f"{__name__}.MyObject.set_foo", autospec=True)
    def test_do_something(self, mock_set_foo, mock_set_bar):
        manager = Mock()
        manager.attach_mock(mock_set_foo, "set_foo_func")
        manager.attach_mock(mock_set_bar, "set_bar_func")
        do_something()
        assert manager.mock_calls == [
            call.set_foo_func(ANY, 3),
            call.set_bar_func(ANY, 4),
        ]
        manager.assert_has_calls([call.set_foo_func(ANY, 3), call.set_bar_func(ANY, 4)])


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


➜  cpython git:(bpo38473) ./python ../backups/bpo21478.py
.
----------------------------------------------------------------------
Ran 1 test in 0.006s

OK
History
Date User Action Args
2019-10-14 17:40:46xtreaksetrecipients: + xtreak, cjw296, michael.foord, Claudiu.Popa, kushal.das, and, mariocj89, iforapsy, Caris Moses
2019-10-14 17:40:46xtreaksetmessageid: <1571074846.5.0.108200238922.issue21478@roundup.psfhosted.org>
2019-10-14 17:40:46xtreaklinkissue21478 messages
2019-10-14 17:40:46xtreakcreate