~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

(gz) Update knownFailure so the reason isn't lost on Python 2.7 (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
825
825
        self.assertEndsWith(sio.getvalue(), "OK    50002ms\n")
826
826
 
827
827
    def test_known_failure(self):
828
 
        """A KnownFailure being raised should trigger several result actions."""
 
828
        """Using knownFailure should trigger several result actions."""
829
829
        class InstrumentedTestResult(tests.ExtendedTestResult):
830
830
            def stopTestRun(self): pass
831
831
            def report_tests_starting(self): pass
834
834
        result = InstrumentedTestResult(None, None, None, None)
835
835
        class Test(tests.TestCase):
836
836
            def test_function(self):
837
 
                raise tests.KnownFailure('failed!')
 
837
                self.knownFailure('failed!')
838
838
        test = Test("test_function")
839
839
        test.run(result)
840
840
        # it should invoke 'report_known_failure'.
856
856
            descriptions=0,
857
857
            verbosity=2,
858
858
            )
859
 
        test = self.get_passing_test()
860
 
        result.startTest(test)
861
 
        prefix = len(result_stream.getvalue())
862
 
        # the err parameter has the shape:
863
 
        # (class, exception object, traceback)
864
 
        # KnownFailures dont get their tracebacks shown though, so we
865
 
        # can skip that.
866
 
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
867
 
        result.report_known_failure(test, err)
868
 
        output = result_stream.getvalue()[prefix:]
869
 
        lines = output.splitlines()
870
 
        self.assertContainsRe(lines[0], r'XFAIL *\d+ms$')
871
 
        if sys.version_info > (2, 7):
872
 
            self.expectFailure("_ExpectedFailure on 2.7 loses the message",
873
 
                self.assertNotEqual, lines[1], '    ')
874
 
        self.assertEqual(lines[1], '    foo')
875
 
        self.assertEqual(2, len(lines))
 
859
        _get_test("test_xfail").run(result)
 
860
        self.assertContainsRe(result_stream.getvalue(),
 
861
            "\n\\S+\\.test_xfail\\s+XFAIL\\s+\\d+ms\n"
 
862
            "\\s*(?:Text attachment: )?reason"
 
863
            "(?:\n-+\n|: {{{)"
 
864
            "this_fails"
 
865
            "(?:\n-+\n|}}}\n)")
876
866
 
877
867
    def get_passing_test(self):
878
868
        """Return a test object that can't be run usefully."""
958
948
    def test_strict_with_known_failure(self):
959
949
        result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
960
950
                                             verbosity=1)
961
 
        test = self.get_passing_test()
962
 
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
963
 
        result.addExpectedFailure(test, err)
 
951
        test = _get_test("test_xfail")
 
952
        test.run(result)
964
953
        self.assertFalse(result.wasStrictlySuccessful())
965
954
        self.assertEqual(None, result._extractBenchmarkTime(test))
966
955