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
Cannot deepcopy unittest.TestCase instances #49910
Comments
Here's a demonstration of the bug: >>> from unittest import TestCase
>>> class MyTest(TestCase):
... def test_foo(self): pass
...
>>> tc = MyTest('test_foo')
>>> import copy
>>> copy.deepcopy(tc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/stow/py2.7/lib/python2.7/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/stow/py2.7/lib/python2.7/copy.py", line 338, in
_reconstruct
state = deepcopy(state, memo)
File "/usr/local/stow/py2.7/lib/python2.7/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/local/stow/py2.7/lib/python2.7/copy.py", line 255, in
_deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/stow/py2.7/lib/python2.7/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/local/stow/py2.7/lib/python2.7/copy.py", line 255, in
_deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/stow/py2.7/lib/python2.7/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/stow/py2.7/lib/python2.7/copy.py", line 323, in
_reconstruct
y = callable(*args)
File "/usr/local/bin/../stow/py2.7/lib/python2.7/copy_reg.py", line
93, in __newobj__
return cls.__new__(cls, *args)
TypeError: instancemethod expected at least 2 arguments, got 0 This regression breaks bzr's test suite, which copies test objects to I suspect the __test_equality_funcs on TestCase is the problem: >>> tc.__dict__
{'_testMethodDoc': None, '_TestCase__type_equality_funcs': {<type
'dict'>: <bound method MyTest.assertDictEqual of <__main__.MyTest
testMethod=test_foo>>, <type 'tuple'>: <bound method
MyTest.assertTupleEqual of <__main__.MyTest testMethod=test_foo>>, <type
'frozenset'>: <bound method MyTest.assertSetEqual of <__main__.MyTest
testMethod=test_foo>>, <type 'list'>: <bound method
MyTest.assertListEqual of <__main__.MyTest testMethod=test_foo>>, <type
'set'>: <bound method MyTest.assertSetEqual of <__main__.MyTest
testMethod=test_foo>>}, '_testMethodName': 'test_foo'} copy.deepcopy can't deepcopy bound methods, reasonably enough. |
This is a workaround: import copy
copy._deepcopy_dispatch[types.MethodType] = copy._deepcopy_atomic |
We can fix this by wrapping the assert functions in our assert register |
Fixed in revision 71043. |
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: