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 spark
Recipients spark
Date 2019-05-07.14:44:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1557240261.05.0.942052494289.issue36834@roundup.psfhosted.org>
In-reply-to
Content
The expectation is that the __module__ attribute for a patched function should persist after patching.

Minimal test case is attached. Simply run pytest in a venv with the files.

Output:
def test_zxc():
        with mock.patch.object(mymodule, 'asd', side_effect=mymodule.asd, autospec=True) as spy_asd:
>           assert spy_asd.__module__ == 'mymodule'
E           AssertionError: assert None == 'mymodule'
E            +  where None = <function asd at 0x7fe4cd6fd620>.__module__

test_mymodule.py:8: AssertionError

Originally reported at https://github.com/pytest-dev/pytest-mock/issues/146 before it was determined this was a unittest.mock issue.

Happens on both Python 2.7 and 3.7. Probably not really tied to a specific Python version and more of mock library issue.

My local venv:
Python 3.7.2
pytest 4.4.1
History
Date User Action Args
2019-05-07 14:44:21sparksetrecipients: + spark
2019-05-07 14:44:21sparksetmessageid: <1557240261.05.0.942052494289.issue36834@roundup.psfhosted.org>
2019-05-07 14:44:21sparklinkissue36834 messages
2019-05-07 14:44:20sparkcreate