~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

(jameinel) Teach TestCase.overrideAttr how to handle attributes that don't
 exist yet. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1751
1751
 
1752
1752
        :returns: The actual attr value.
1753
1753
        """
1754
 
        value = getattr(obj, attr_name)
1755
1754
        # The actual value is captured by the call below
1756
 
        self.addCleanup(setattr, obj, attr_name, value)
 
1755
        value = getattr(obj, attr_name, _unitialized_attr)
 
1756
        if value is _unitialized_attr:
 
1757
            # When the test completes, the attribute should not exist, but if
 
1758
            # we aren't setting a value, we don't need to do anything.
 
1759
            if new is not _unitialized_attr:
 
1760
                self.addCleanup(delattr, obj, attr_name)
 
1761
        else:
 
1762
            self.addCleanup(setattr, obj, attr_name, value)
1757
1763
        if new is not _unitialized_attr:
1758
1764
            setattr(obj, attr_name, new)
1759
1765
        return value