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 marchant.jm
Recipients marchant.jm
Date 2022-02-09.11:54:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644407640.16.0.14753457907.issue46690@roundup.psfhosted.org>
In-reply-to
Content
When using `create_autospec()` to create a mock object, it doesn't respect values passed through in the style described for passing mock configurations in the Mock constructor (https://docs.python.org/3.8/library/unittest.mock.html#unittest.mock.Mock.configure_mock). Instead, they seem to get discarded somewhere here (https://github.com/python/cpython/blob/77bab59c8a1f04922bb975cc4f11e5323d1d379d/Lib/unittest/mock.py#L2693-L2741).

Here's a simple test case:
```
from unittest.mock import create_autospec

class Test:
    def test_method(self):
        pass

autospec_mock = create_autospec(Test, instance=True, **{"test_method.side_effect": ValueError})

# Should throw a ValueError exception
autospec_mock.test_method()

# Assign manually
autospec_mock.test_method.side_effect = ValueError
# Throws as expected
autospec_mock.test_method()
```
History
Date User Action Args
2022-02-09 11:54:00marchant.jmsetrecipients: + marchant.jm
2022-02-09 11:54:00marchant.jmsetmessageid: <1644407640.16.0.14753457907.issue46690@roundup.psfhosted.org>
2022-02-09 11:54:00marchant.jmlinkissue46690 messages
2022-02-09 11:54:00marchant.jmcreate