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 spiv
Recipients spiv
Date 2009-04-02.00:27:50
SpamBayes Score 1.1677703e-10
Marked as misclassified No
Message-id <1238632074.64.0.545150493098.issue5660@psf.upfronthosting.co.za>
In-reply-to
Content
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
run the same test against multiple scenarios (e.g. to run all the same
tests against all the implementations of bzrlib.transport.Transport,
such as HTTPTransport and SFTPTransport.) 
<https://launchpad.net/testtools> also implements test parameterisation
in this way, and it is extremely useful.

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.
History
Date User Action Args
2009-04-02 00:27:54spivsetrecipients: + spiv
2009-04-02 00:27:54spivsetmessageid: <1238632074.64.0.545150493098.issue5660@psf.upfronthosting.co.za>
2009-04-02 00:27:53spivlinkissue5660 messages
2009-04-02 00:27:51spivcreate