summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfilters/subunit-filter2
-rw-r--r--python/subunit/test_results.py35
-rw-r--r--python/subunit/tests/test_subunit_filter.py14
3 files changed, 37 insertions, 14 deletions
diff --git a/filters/subunit-filter b/filters/subunit-filter
index 7f5620f..66759ff 100755
--- a/filters/subunit-filter
+++ b/filters/subunit-filter
@@ -97,7 +97,7 @@ def _make_regexp_filter(with_regexps, without_regexps):
with_re = with_regexps and _compile_re_from_list(with_regexps)
without_re = without_regexps and _compile_re_from_list(without_regexps)
- def check_regexps(test, outcome, err, details):
+ def check_regexps(test, outcome, err, details, tags):
"""Check if this test and error match the regexp filters."""
test_str = str(test) + outcome + str(err) + str(details)
if with_re and not with_re.search(test_str):
diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py
index 0c6fbd5..25c5c77 100644
--- a/python/subunit/test_results.py
+++ b/python/subunit/test_results.py
@@ -308,11 +308,7 @@ class _PredicateFilter(TestResultDecorator):
# 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)
+ return self._predicate(test, outcome, error, details, tags)
def addError(self, test, err=None, details=None):
if (self.filter_predicate(test, 'error', err, details)):
@@ -425,20 +421,33 @@ class TestResultFilter(_PredicateFilter):
"""
predicates = []
if filter_error:
- predicates.append(lambda t, outcome, e, d: outcome != 'error')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'error')
if filter_failure:
- predicates.append(lambda t, outcome, e, d: outcome != 'failure')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'failure')
if filter_success:
- predicates.append(lambda t, outcome, e, d: outcome != 'success')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'success')
if filter_skip:
- predicates.append(lambda t, outcome, e, d: outcome != 'skip')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'skip')
if filter_xfail:
- predicates.append(lambda t, outcome, e, d: outcome != 'expectedfailure')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'expectedfailure')
if filter_predicate is not None:
- predicates.append(filter_predicate)
+ def compat(test, outcome, error, details, tags):
+ # 0.0.7 and earlier did not support the 'tags' parameter.
+ try:
+ return filter_predicate(
+ test, outcome, error, details, tags)
+ except TypeError:
+ return filter_predicate(test, outcome, error, details)
+ predicates.append(compat)
predicate = (
- lambda test, outcome, err, details:
- all_true(p(test, outcome, err, details) for p in predicates))
+ lambda test, outcome, err, details, tags:
+ all_true(p(test, outcome, err, details, tags)
+ for p in predicates))
super(TestResultFilter, self).__init__(result, predicate)
if fixup_expected_failures is None:
self._fixup_expected_failures = frozenset()
diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py
index 83b9240..5bbf581 100644
--- a/python/subunit/tests/test_subunit_filter.py
+++ b/python/subunit/tests/test_subunit_filter.py
@@ -151,6 +151,8 @@ xfail todo
def test_filter_predicate(self):
"""You can filter by predicate callbacks"""
+ # 0.0.7 and earlier did not support the 'tags' parameter, so we need
+ # to test that we still support behaviour without it.
filtered_result = unittest.TestResult()
def filter_cb(test, outcome, err, details):
return outcome == 'success'
@@ -161,6 +163,18 @@ xfail todo
# Only success should pass
self.assertEqual(1, filtered_result.testsRun)
+ def test_filter_predicate_with_tags(self):
+ """You can filter by predicate callbacks that accept tags"""
+ filtered_result = unittest.TestResult()
+ def filter_cb(test, outcome, err, details, tags):
+ return outcome == 'success'
+ result_filter = TestResultFilter(filtered_result,
+ filter_predicate=filter_cb,
+ filter_success=False)
+ self.run_tests(result_filter)
+ # Only success should pass
+ self.assertEqual(1, filtered_result.testsRun)
+
def test_time_ordering_preserved(self):
# Passing a subunit stream through TestResultFilter preserves the
# relative ordering of 'time' directives and any other subunit