diff options
| author | Robert Collins <robertc@robertcollins.net> | 2009-10-07 23:19:12 +1100 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2009-10-07 23:19:12 +1100 |
| commit | 446d6f69537d2fb2bff212e3f8ebc3f36b525740 (patch) | |
| tree | f917778178e0ddc9090e1d53a945397cd9a8e357 /python/subunit/__init__.py | |
| parent | aa757dce0d1ca43a66a5f008e05699a0230b0d59 (diff) | |
| download | subunit-git-446d6f69537d2fb2bff212e3f8ebc3f36b525740.tar.gz | |
Hook addError up to the details protocol.
Diffstat (limited to 'python/subunit/__init__.py')
| -rw-r--r-- | python/subunit/__init__.py | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 9d021fe..1c6937c 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``, ``addFailure`` take an optional -keyword parameter ``details`` which can be used instead of the usual python -unittest parameter. +The test outcome methods ``addSuccess``, ``addError``, ``addFailure`` 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 @@ -473,12 +473,20 @@ class TestProtocolClient(unittest.TestResult): unittest.TestResult.__init__(self) self._stream = stream - def addError(self, test, error): - """Report an error in test test.""" - self._stream.write("error: %s [\n" % test.id()) - for line in self._exc_info_to_string(error, test).splitlines(): - self._stream.write("%s\n" % line) - self._stream.write("]\n") + def addError(self, test, error=None, details=None): + """Report an error 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("error", test, error=error, details=details) def addFailure(self, test, error=None, details=None): """Report a failure in test test. @@ -493,7 +501,24 @@ class TestProtocolClient(unittest.TestResult): :param details: New Testing-in-python drafted API; a dict from string to subunit.Content objects. """ - self._stream.write("failure: %s" % test.id()) + self._addOutcome("failure", test, error=error, details=details) + + def _addOutcome(self, outcome, test, error=None, details=None): + """Report a failure in test test. + + Only one of error and details should be provided: conceptually there + are two separate methods: + addOutcome(self, test, error) + addOutcome(self, test, details) + + :param outcome: A string describing the outcome - used as the + event name in the subunit stream. + :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._stream.write("%s: %s" % (outcome, test.id())) if error is None and details is None: raise ValueError if error is not None: |
