diff options
| author | Robert Collins <robertc@robertcollins.net> | 2009-10-09 14:42:46 +1100 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2009-10-09 14:42:46 +1100 |
| commit | af6f8521c7d26966b63c66d164cc5a7e01d2e86b (patch) | |
| tree | 0aff25f4953781ec76ff371996b448a39b3eee98 /python | |
| parent | 1af90d7941a17338fc9a296ec5dce7ab79ade550 (diff) | |
| download | subunit-git-af6f8521c7d26966b63c66d164cc5a7e01d2e86b.tar.gz | |
Add support for addExpectedFailure in the Subunit python serialiser.
Diffstat (limited to 'python')
| -rw-r--r-- | python/subunit/__init__.py | 21 | ||||
| -rw-r--r-- | python/subunit/tests/test_test_protocol.py | 25 |
2 files changed, 43 insertions, 3 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index a63a433..b5d7d76 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -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. diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 4434710..e909d3f 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -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( |
