Add support for addExpectedFailure in the Subunit python serialiser.
authorRobert Collins <robertc@robertcollins.net>
Fri, 9 Oct 2009 03:42:46 +0000 (14:42 +1100)
committerRobert Collins <robertc@robertcollins.net>
Fri, 9 Oct 2009 03:42:46 +0000 (14:42 +1100)
NEWS
python/subunit/__init__.py
python/subunit/tests/test_test_protocol.py

diff --git a/NEWS b/NEWS
index 19a38f130751a4511d1a2a6e475bae6622196a85..77f4d1713ca30fb2adc376eb5763ec5c99f3738a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ subunit release notes
 
   IMPROVEMENTS:
 
+    * In the python API addExpectedFailure from python 2.7/3.1 is now
+      supported.
+
     * INSTALLDIRS can be set to control the perl MakeMaker 'INSTALLDIRS'
       viarable when installing.
 
index a63a4331d177f7caec2ea451d2928e3ed4937c93..b5d7d76edf5454647bc263e510bf9ed9bdcd5fb3 100644 (file)
@@ -46,9 +46,9 @@ will either lose fidelity (for instance, folding expected failures to success
 in Python versions < 2.7 or 3.1), or discard the extended data (for extra
 details, tags, timestamping and progress markers).
 
-The test outcome methods ``addSuccess``, ``addError``, ``addFailure``,
-``addSkip`` take an optional keyword parameter ``details`` which can be used
-instead of the usual python unittest parameter.
+The test outcome methods ``addSuccess``, ``addError``, ``addExpectedFailure``,
+``addFailure``, ``addSkip`` take an optional keyword parameter ``details``
+which can be used instead of the usual python unittest parameter.
 When used the value of details should be a dict from ``string`` to 
 ``subunit.content.Content`` objects. This is a draft API being worked on with
 the Python Testing In Python mail list, with the goal of permitting a common
@@ -490,6 +490,21 @@ class TestProtocolClient(unittest.TestResult):
         """
         self._addOutcome("error", test, error=error, details=details)
 
+    def addExpectedFailure(self, test, error=None, details=None):
+        """Report an expected failure in test test.
+        
+        Only one of error and details should be provided: conceptually there
+        are two separate methods:
+            addError(self, test, error)
+            addError(self, test, details)
+
+        :param error: Standard unittest positional argument form - an
+            exc_info tuple.
+        :param details: New Testing-in-python drafted API; a dict from string
+            to subunit.Content objects.
+        """
+        self._addOutcome("xfail", test, error=error, details=details)
+
     def addFailure(self, test, error=None, details=None):
         """Report a failure in test test.
         
index 44347108016d923d2b16f206768ab4ac30664f67..e909d3fb8f771469e45e3a08fa82208342fab713 100644 (file)
@@ -1133,6 +1133,31 @@ class TestTestProtocolClient(unittest.TestCase):
             "25\nRemoteException: boo qux\n0\n"
             "]\n" % self.test.id())
 
+    def test_add_expected_failure(self):
+        """Test addExpectedFailure on a TestProtocolClient."""
+        self.protocol.addExpectedFailure(
+            self.test, subunit.RemoteError("phwoar crikey"))
+        self.assertEqual(
+            self.io.getvalue(),
+            'xfail: %s [\n'
+            "RemoteException: phwoar crikey\n"
+            "]\n" % self.test.id())
+
+    def test_add_expected_failure_details(self):
+        """Test addExpectedFailure on a TestProtocolClient with details."""
+        self.protocol.addExpectedFailure(
+            self.test, details=self.sample_tb_details)
+        self.assertEqual(
+            self.io.getvalue(),
+            "xfail: %s [ multipart\n"
+            "Content-Type: text/plain\n"
+            "something\n"
+            "15\nserialised\nform0\n"
+            "Content-Type: text/x-traceback;language=python\n"
+            "traceback\n"
+            "25\nRemoteException: boo qux\n0\n"
+            "]\n" % self.test.id())
+
     def test_add_skip(self):
         """Test addSkip on a TestProtocolClient."""
         self.protocol.addSkip(