From 8ff7d39c1e1e247d860053026d6fd0867379adb0 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Tue, 10 Apr 2012 14:26:44 +0100 Subject: Allow the predicate to filter tags. --- python/subunit/test_results.py | 13 ++++++++++++- python/subunit/tests/test_test_results.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py index 92e0310..0c6fbd5 100644 --- a/python/subunit/test_results.py +++ b/python/subunit/test_results.py @@ -80,6 +80,10 @@ class TestResultDecorator(object): def wasSuccessful(self): return self.decorated.wasSuccessful() + @property + def current_tags(self): + return self.decorated.current_tags + @property def shouldStop(self): return self.decorated.shouldStop @@ -301,7 +305,14 @@ class _PredicateFilter(TestResultDecorator): self._buffered_calls = [] def filter_predicate(self, test, outcome, error, details): - return self._predicate(test, outcome, error, details) + # XXX: ExtendedToOriginalDecorator doesn't properly wrap current_tags. + # https://bugs.launchpad.net/testtools/+bug/978027 + tags = getattr(self.decorated, 'current_tags', frozenset()) + # 0.0.7 and earlier did not support the 'tags' parameter. + try: + return self._predicate(test, outcome, error, details, tags) + except TypeError: + return self._predicate(test, outcome, error, details) def addError(self, test, err=None, details=None): if (self.filter_predicate(test, 'error', err, details)): diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 6beb57a..2bec7e3 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -56,6 +56,16 @@ class AssertBeforeTestResult(LoggingDecorator): super(AssertBeforeTestResult, self)._before_event() +class TestTestResultDecorator(unittest.TestCase): + + def test_current_tags(self): + result = ExtendedTestResult() + decorator = subunit.test_results.TestResultDecorator(result) + decorator.tags(set('foo'), set()) + self.assertEqual(set('foo'), decorator.current_tags) + self.assertEqual(decorator.current_tags, result.current_tags) + + class TimeCapturingResult(unittest.TestResult): def __init__(self): -- cgit v1.2.1