Rev 6054: (gz) Update knownFailure so the reason isn't lost on Python 2.7 (Martin [gz]) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sat Aug 6 03:52:37 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6054 [merge]
revision-id: pqm at pqm.ubuntu.com-20110806035234-q75axfes2gm01kne
parent: pqm at pqm.ubuntu.com-20110805191820-dyms8ui5i6le4xtc
parent: gzlist at googlemail.com-20110805212639-txtd033op7rl5chr
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2011-08-06 03:52:34 +0000
message:
  (gz) Update knownFailure so the reason isn't lost on Python 2.7 (Martin [gz])
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2011-08-02 01:10:27 +0000
+++ b/bzrlib/tests/__init__.py	2011-08-05 21:26:39 +0000
@@ -1793,8 +1793,31 @@
         self._preserved_lazy_hooks.clear()
 
     def knownFailure(self, reason):
-        """This test has failed for some known reason."""
-        raise KnownFailure(reason)
+        """Declare that this test fails for a known reason
+
+        Tests that are known to fail should generally be using expectedFailure
+        with an appropriate reverse assertion if a change could cause the test
+        to start passing. Conversely if the test has no immediate prospect of
+        succeeding then using skip is more suitable.
+
+        When this method is called while an exception is being handled, that
+        traceback will be used, otherwise a new exception will be thrown to
+        provide one but won't be reported.
+        """
+        self._add_reason(reason)
+        try:
+            exc_info = sys.exc_info()
+            if exc_info != (None, None, None):
+                self._report_traceback(exc_info)
+            else:
+                try:
+                    raise self.failureException(reason)
+                except self.failureException:
+                    exc_info = sys.exc_info()
+            # GZ 02-08-2011: Maybe cleanup this err.exc_info attribute too?
+            raise testtools.testcase._ExpectedFailure(exc_info)
+        finally:
+            del exc_info
 
     def _suppress_log(self):
         """Remove the log info from details."""

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2011-08-03 14:34:34 +0000
+++ b/bzrlib/tests/test_selftest.py	2011-08-06 03:52:34 +0000
@@ -825,7 +825,7 @@
         self.assertEndsWith(sio.getvalue(), "OK    50002ms\n")
 
     def test_known_failure(self):
-        """A KnownFailure being raised should trigger several result actions."""
+        """Using knownFailure should trigger several result actions."""
         class InstrumentedTestResult(tests.ExtendedTestResult):
             def stopTestRun(self): pass
             def report_tests_starting(self): pass
@@ -834,7 +834,7 @@
         result = InstrumentedTestResult(None, None, None, None)
         class Test(tests.TestCase):
             def test_function(self):
-                raise tests.KnownFailure('failed!')
+                self.knownFailure('failed!')
         test = Test("test_function")
         test.run(result)
         # it should invoke 'report_known_failure'.
@@ -856,23 +856,13 @@
             descriptions=0,
             verbosity=2,
             )
-        test = self.get_passing_test()
-        result.startTest(test)
-        prefix = len(result_stream.getvalue())
-        # the err parameter has the shape:
-        # (class, exception object, traceback)
-        # KnownFailures dont get their tracebacks shown though, so we
-        # can skip that.
-        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
-        result.report_known_failure(test, err)
-        output = result_stream.getvalue()[prefix:]
-        lines = output.splitlines()
-        self.assertContainsRe(lines[0], r'XFAIL *\d+ms$')
-        if sys.version_info > (2, 7):
-            self.expectFailure("_ExpectedFailure on 2.7 loses the message",
-                self.assertNotEqual, lines[1], '    ')
-        self.assertEqual(lines[1], '    foo')
-        self.assertEqual(2, len(lines))
+        _get_test("test_xfail").run(result)
+        self.assertContainsRe(result_stream.getvalue(),
+            "\n\\S+\\.test_xfail\\s+XFAIL\\s+\\d+ms\n"
+            "\\s*(?:Text attachment: )?reason"
+            "(?:\n-+\n|: {{{)"
+            "this_fails"
+            "(?:\n-+\n|}}}\n)")
 
     def get_passing_test(self):
         """Return a test object that can't be run usefully."""
@@ -958,9 +948,8 @@
     def test_strict_with_known_failure(self):
         result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
                                              verbosity=1)
-        test = self.get_passing_test()
-        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
-        result.addExpectedFailure(test, err)
+        test = _get_test("test_xfail")
+        test.run(result)
         self.assertFalse(result.wasStrictlySuccessful())
         self.assertEqual(None, result._extractBenchmarkTime(test))
 

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-08-05 19:18:20 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-08-06 03:52:34 +0000
@@ -164,5 +164,8 @@
   This reduces the overall test suite time by about 10% on my laptop.
   (Andrew Bennetts)
 
+* Update `TestCase.knownFailure` to the testtools way of handling expected
+  failures to resolve Python 2.7 incompatibility. (Martin [gz], #607400)
+
 ..
    vim: tw=74 ft=rst ff=unix




More information about the bazaar-commits mailing list