Merge lp:~spiv/bzr/traceback-accumulation-2.2 into lp:bzr/2.2

Proposed by Andrew Bennetts
Status: Merged
Approved by: Andrew Bennetts
Approved revision: no longer in the source branch.
Merged at revision: 5091
Proposed branch: lp:~spiv/bzr/traceback-accumulation-2.2
Merge into: lp:bzr/2.2
Diff against target: 81 lines (+16/-32)
2 files modified
NEWS (+4/-4)
bzrlib/tests/__init__.py (+12/-28)
To merge this branch: bzr merge lp:~spiv/bzr/traceback-accumulation-2.2
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+35778@code.launchpad.net

Commit message

Replace TestCase__copy__ hack with more direct workaround in clone_test.

Description of the change

This is a more conservative workaround than the previous hack (which seems to mysteriously fail when sent to land in lp:bzr, but landed just fine in lp:bzr/2.2).

It removes the __copy__ method in favour of making clone_test explicitly reset just the details dict (given that the other mutable, shared attributes aren't causing us any grief).

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

+1, to my mind this is arguably a cleaner fix anyhow.

review: Approve
Revision history for this message
Andrew Bennetts (spiv) wrote :

Yes, I agree it's cleaner. With hindsight I'm not sure why I didn't do this in the first place. :)

Thanks for the speedy review.

Revision history for this message
Andrew Bennetts (spiv) wrote :

sent to pqm by email

Revision history for this message
Vincent Ladeuil (vila) wrote :

Anonymous XXX tend to lost their value over time, this will be later fixed in trunk anyway right ?

Revision history for this message
Andrew Bennetts (spiv) wrote :

Vincent Ladeuil wrote:
> Anonymous XXX tend to lost their value over time, this will be later fixed in trunk anyway right ?

The goal is to fix this in testtools. Then we can remove this
workaround (and probably also remove 'clone_test' entirely in favour of
the testtools equivalent, clone_test_with_new_id).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-09-16 07:12:32 +0000
+++ NEWS 2010-09-17 05:27:47 +0000
@@ -75,10 +75,10 @@
75*******75*******
7676
77* Tracebacks from a parameterized test are no longer reported against every77* Tracebacks from a parameterized test are no longer reported against every
78 parameterization of that test. This was done by adding a custom78 parameterization of that test. This was done by adding a hack to
79 ``__copy__`` method to TestCase, so that ``multiply_tests`` no longer79 ``bzrlib.tests.clone_test`` so that it no longer causes
80 causes testtools.TestCase instances to share a details dict (or other80 testtools.TestCase instances to share a details dict.
81 mutable attributes). (Andrew Bennetts, #625574)81 (Andrew Bennetts, #625574)
8282
8383
84bzr 2.284bzr 2.2
8585
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2010-09-15 06:44:55 +0000
+++ bzrlib/tests/__init__.py 2010-09-17 05:27:47 +0000
@@ -799,15 +799,6 @@
799 _log_file_name = None799 _log_file_name = None
800 # record lsprof data when performing benchmark calls.800 # record lsprof data when performing benchmark calls.
801 _gather_lsprof_in_benchmarks = False801 _gather_lsprof_in_benchmarks = False
802 # Mutable attributes defined in bzrlib.tests.TestCase and
803 # testtools.TestCase that should not be shallow copied by clone_test.
804 # This is ugly, but probably the best we can do until testtools provide a
805 # nicer way to deal with this, see
806 # <https://bugs.launchpad.net/testtools/+bug/637725>.
807 _attrs_to_deepcopy = (
808 '_cleanups', 'exception_handlers', '_unique_id_gen',
809 '_traceback_id_gen', '_TestCase__details',
810 '_TestCase__exception_handlers')
811802
812 def __init__(self, methodName='testMethod'):803 def __init__(self, methodName='testMethod'):
813 super(TestCase, self).__init__(methodName)804 super(TestCase, self).__init__(methodName)
@@ -818,25 +809,6 @@
818 self.exception_handlers.insert(0,809 self.exception_handlers.insert(0,
819 (TestNotApplicable, self._do_not_applicable))810 (TestNotApplicable, self._do_not_applicable))
820811
821 def __copy__(self):
822 # XXX: This method works around the lack of a way to correctly clone a
823 # test with current testtools. See
824 # <https://bugs.launchpad.net/testtools/+bug/637725>.
825 # The work around is to:
826 # - shallow copy self.__dict__
827 # - deep copy individual attributes in the _attrs_to_deepcopy black
828 # list.
829 # - create a new instance (skipping __init__) with the new __dict__.
830 attrs = self.__dict__.copy()
831 for attr_name in self._attrs_to_deepcopy:
832 if attr_name in attrs:
833 attrs[attr_name] = copy.deepcopy(attrs[attr_name])
834 # Some Python voodoo to create an instance without invoking its
835 # __init__, because we've already constructed the __dict__ to use.
836 new_instance = self.__class__.__new__(self.__class__)
837 new_instance.__dict__ = attrs
838 return new_instance
839
840 def setUp(self):812 def setUp(self):
841 super(TestCase, self).setUp()813 super(TestCase, self).setUp()
842 for feature in getattr(self, '_test_needs_features', []):814 for feature in getattr(self, '_test_needs_features', []):
@@ -4080,6 +4052,18 @@
4080 """4052 """
4081 new_test = copy.copy(test)4053 new_test = copy.copy(test)
4082 new_test.id = lambda: new_id4054 new_test.id = lambda: new_id
4055 # XXX: Workaround <https://bugs.launchpad.net/testtools/+bug/637725>, which
4056 # causes cloned tests to share the 'details' dict. This makes it hard to
4057 # read the test output for parameterized tests, because tracebacks will be
4058 # associated with irrelevant tests.
4059 try:
4060 details = new_test._TestCase__details
4061 except AttributeError:
4062 # must be a different version of testtools than expected. Do nothing.
4063 pass
4064 else:
4065 # Reset the '__details' dict.
4066 new_test._TestCase__details = {}
4083 return new_test4067 return new_test
40844068
40854069

Subscribers

People subscribed via source and target branches