~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-04 00:54:11 UTC
  • mfrom: (1551.13.10 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20070404005411-46c388fbf2acf940
Implement TestCase.expectFailure

Show diffs side-by-side

added added

removed removed

Lines of Context:
920
920
            self.fail("%r is an instance of %s rather than %s" % (
921
921
                obj, obj.__class__, kls))
922
922
 
 
923
    def expectFailure(self, reason, assertion, *args, **kwargs):
 
924
        """Invoke a test, expecting it to fail for the given reason.
 
925
 
 
926
        This is for assertions that ought to succeed, but currently fail.
 
927
        (The failure is *expected* but not *wanted*.)
 
928
 
 
929
        Intended to be used with a callable that raises AssertionError as the
 
930
        'assertion' parameter.  args and kwargs are passed to the 'assertion'.
 
931
 
 
932
        Raises KnownFailure if the test fails.  Raises AssertionError if the
 
933
        test succeeds.
 
934
 
 
935
        example usage::
 
936
          self.expectFailure('File creation is broken', self.failUnlessExists,
 
937
                             'path/that/should/exist')
 
938
        """
 
939
        try:
 
940
            assertion(*args, **kwargs)
 
941
        except AssertionError:
 
942
            raise KnownFailure(reason)
 
943
        else:
 
944
            self.fail('Unexpected success.  Should have failed: %s' % reason)
 
945
 
923
946
    def _capture_warnings(self, a_callable, *args, **kwargs):
924
947
        """A helper for callDeprecated and applyDeprecated.
925
948