-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MagicMock specialisation instance can no longer be passed to new MagicMock instance #83759
Comments
This is my first bug logged here, I've tried to follow the guideline and search for this issue; please let me know if I missed anything. Summary: Repro: What happens: Traceback (most recent call last):
File "<...>", line <..>, in test_raw_magic_moc_passing_thru_single_pos
mock_object = mock.MagicMock(mock_param) # error is here, instantiating another object
File "/usr/lib64/python3.9/unittest/mock.py", line 408, in __new__
if spec_arg and _is_async_obj(spec_arg):
File "/usr/lib64/python3.9/unittest/mock.py", line 2119, in __get__
return self.create_mock()
File "/usr/lib64/python3.9/unittest/mock.py", line 2112, in create_mock
m = parent._get_child_mock(name=entry, _new_name=entry,
File "/usr/lib64/python3.9/unittest/mock.py", line 1014, in _get_child_mock
return klass(**kw)
TypeError: __init__() got an unexpected keyword argument 'name' Code demonstrating the problem: import unittest
from unittest import mock
class TestMockMagicAssociativeHierarchies(unittest.TestCase):
""" Mimicing real-world testing where we mock a base-class
def test_raw_magic_moc_passing_thru_single_pos(self):
""" REGRESSION: Python3.8 (inc Python3.9)
def test_raw_magic_moc_passing_thru_single_kwarg(self):
""" REGRESSION: Python3.8 (inc Python3.9)
def test_mock_as_param_no_inheritance(self):
""" PASSES
def test_mock_as_param_no_init_override(self):
""" PASSES
def test_init_with_args_n_kwargs_passthru(self):
""" PASSES
def test_init_with_args_n_kwargs_modify_kwargs(self):
""" PASSES
def test_init_with_args_n_kwargs_modify_args(self):
""" PASSES
|
Minor correction: The regression was only tested on Python 3.9.0a2 (Fedora), Python 3.9a3 (OSX), CPython's master (build from source) and the latest non-prerelease versions of python 3.5, 3.6, 3.7, and 3.8. Tested on OSX and Fedora 31. |
Having not looked deeply at it but with the reproducer, running a quick bisect, it points to this commit: 77b3b77 |
I am looking at reproducing this and creating a short example of where this fails. Will look further into more details of why this doesn't work. |
Here's the example I ran, that indeed fails in Python 3.8 and Python 3.9 (with different errors) and works in Python 3.7. from unittest.mock import MagicMock
class CustomMock(MagicMock):
def __init__(self):
super().__init__(__something__='something')
mock = CustomMock()
MagicMock(mock) In Python 3.8 the error is TypeError: __init__() got an unexpected keyword argument '_new_parent'. In Python 3.9 the error is TypeError: __init__() got an unexpected keyword argument 'name'. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: