~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Andrew Bennetts
  • Date: 2010-09-17 04:35:23 UTC
  • mfrom: (5050.17.20 2.2)
  • mto: This revision was merged to the branch mainline in revision 5431.
  • Revision ID: andrew.bennetts@canonical.com-20100917043523-c5t63gmvxqxmqh5j
Merge lp:bzr/2.2, including fixes for #625574, #636930, #254278.

Show diffs side-by-side

added added

removed removed

Lines of Context:
814
814
    _log_file = None
815
815
    # record lsprof data when performing benchmark calls.
816
816
    _gather_lsprof_in_benchmarks = False
 
817
    # Mutable attributes defined in bzrlib.tests.TestCase and
 
818
    # testtools.TestCase that should not be shallow copied by clone_test.
 
819
    # This is ugly, but probably the best we can do until testtools provide a
 
820
    # nicer way to deal with this, see
 
821
    # <https://bugs.launchpad.net/testtools/+bug/637725>.
 
822
    _attrs_to_deepcopy = (
 
823
        '_cleanups', 'exception_handlers', '_unique_id_gen',
 
824
        '_traceback_id_gen', '_TestCase__details',
 
825
        '_TestCase__exception_handlers')
817
826
 
818
827
    def __init__(self, methodName='testMethod'):
819
828
        super(TestCase, self).__init__(methodName)
823
832
        self.exception_handlers.insert(0,
824
833
            (TestNotApplicable, self._do_not_applicable))
825
834
 
 
835
    def __copy__(self):
 
836
        # XXX: This method works around the lack of a way to correctly clone a
 
837
        # test with current testtools.  See
 
838
        # <https://bugs.launchpad.net/testtools/+bug/637725>.
 
839
        # The work around is to:
 
840
        #  - shallow copy self.__dict__
 
841
        #  - deep copy individual attributes in the _attrs_to_deepcopy black
 
842
        #    list.
 
843
        #  - create a new instance (skipping __init__) with the new __dict__.
 
844
        attrs = self.__dict__.copy()
 
845
        for attr_name in self._attrs_to_deepcopy:
 
846
            if attr_name in attrs:
 
847
                attrs[attr_name] = copy.deepcopy(attrs[attr_name])
 
848
        # Some Python voodoo to create an instance without invoking its
 
849
        # __init__, because we've already constructed the __dict__ to use.
 
850
        new_instance = self.__class__.__new__(self.__class__)
 
851
        new_instance.__dict__ = attrs
 
852
        return new_instance
 
853
 
826
854
    def setUp(self):
827
855
        super(TestCase, self).setUp()
828
856
        for feature in getattr(self, '_test_needs_features', []):