Rev 5091: (spiv) Replace TestCase__copy__ hack with more direct workaround in in file:///home/pqm/archives/thelove/bzr/2.2/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Sep 17 07:46:11 BST 2010


At file:///home/pqm/archives/thelove/bzr/2.2/

------------------------------------------------------------
revno: 5091 [merge]
revision-id: pqm at pqm.ubuntu.com-20100917064608-qm7k0sez9941oj85
parent: pqm at pqm.ubuntu.com-20100916071232-2p0bokcnlnphk0aj
parent: andrew.bennetts at canonical.com-20100917052320-lq2bhazlb6qdd581
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.2
timestamp: Fri 2010-09-17 07:46:08 +0100
message:
  (spiv) Replace TestCase__copy__ hack with more direct workaround in
   clone_test. (Andrew Bennetts)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
=== modified file 'NEWS'
--- a/NEWS	2010-09-16 07:12:32 +0000
+++ b/NEWS	2010-09-17 06:46:08 +0000
@@ -75,10 +75,10 @@
 *******
 
 * Tracebacks from a parameterized test are no longer reported against every
-  parameterization of that test.  This was done by adding a custom
-  ``__copy__`` method to TestCase, so that ``multiply_tests`` no longer
-  causes testtools.TestCase instances to share a details dict (or other
-  mutable attributes).  (Andrew Bennetts, #625574)
+  parameterization of that test.  This was done by adding a hack to
+  ``bzrlib.tests.clone_test`` so that it no longer causes
+  testtools.TestCase instances to share a details dict.
+  (Andrew Bennetts, #625574)
 
 
 bzr 2.2

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-09-15 06:44:55 +0000
+++ b/bzrlib/tests/__init__.py	2010-09-17 05:23:20 +0000
@@ -799,15 +799,6 @@
     _log_file_name = None
     # record lsprof data when performing benchmark calls.
     _gather_lsprof_in_benchmarks = False
-    # Mutable attributes defined in bzrlib.tests.TestCase and
-    # testtools.TestCase that should not be shallow copied by clone_test.
-    # This is ugly, but probably the best we can do until testtools provide a
-    # nicer way to deal with this, see
-    # <https://bugs.launchpad.net/testtools/+bug/637725>.
-    _attrs_to_deepcopy = (
-        '_cleanups', 'exception_handlers', '_unique_id_gen',
-        '_traceback_id_gen', '_TestCase__details',
-        '_TestCase__exception_handlers')
 
     def __init__(self, methodName='testMethod'):
         super(TestCase, self).__init__(methodName)
@@ -818,25 +809,6 @@
         self.exception_handlers.insert(0,
             (TestNotApplicable, self._do_not_applicable))
 
-    def __copy__(self):
-        # XXX: This method works around the lack of a way to correctly clone a
-        # test with current testtools.  See
-        # <https://bugs.launchpad.net/testtools/+bug/637725>.
-        # The work around is to:
-        #  - shallow copy self.__dict__
-        #  - deep copy individual attributes in the _attrs_to_deepcopy black
-        #    list.
-        #  - create a new instance (skipping __init__) with the new __dict__.
-        attrs = self.__dict__.copy()
-        for attr_name in self._attrs_to_deepcopy:
-            if attr_name in attrs:
-                attrs[attr_name] = copy.deepcopy(attrs[attr_name])
-        # Some Python voodoo to create an instance without invoking its
-        # __init__, because we've already constructed the __dict__ to use.
-        new_instance = self.__class__.__new__(self.__class__)
-        new_instance.__dict__ = attrs
-        return new_instance
-
     def setUp(self):
         super(TestCase, self).setUp()
         for feature in getattr(self, '_test_needs_features', []):
@@ -4080,6 +4052,18 @@
     """
     new_test = copy.copy(test)
     new_test.id = lambda: new_id
+    # XXX: Workaround <https://bugs.launchpad.net/testtools/+bug/637725>, which
+    # causes cloned tests to share the 'details' dict.  This makes it hard to
+    # read the test output for parameterized tests, because tracebacks will be
+    # associated with irrelevant tests.
+    try:
+        details = new_test._TestCase__details
+    except AttributeError:
+        # must be a different version of testtools than expected.  Do nothing.
+        pass
+    else:
+        # Reset the '__details' dict.
+        new_test._TestCase__details = {}
     return new_test
 
 




More information about the bazaar-commits mailing list