yellow team mailing list archive
-
yellow team
-
Mailing list archive
-
Message #00773
[Merge] lp:~yellow/subunit/on_filter into lp:subunit
Gary Poster has proposed merging lp:~yellow/subunit/on_filter into lp:subunit.
Requested reviews:
Subunit Developers (subunit)
For more details, see:
https://code.launchpad.net/~yellow/subunit/on_filter/+merge/103968
This branch adds an on_filter keyword argument to TestResultFilter. This is intended to be an approach that can significantly simplify the TestResultFilter subclass in testrepository now, and fix test failures in testrepository when lp:~jml/subunit/filter-tags is merged.
This MP replaces https://code.launchpad.net/~yellow/subunit/test-count/+merge/103717 , and the comments in that MP point to why this branch is of interest to us.
Thank you
--
https://code.launchpad.net/~yellow/subunit/on_filter/+merge/103968
Your team Launchpad Yellow Squad is subscribed to branch lp:~yellow/subunit/on_filter.
=== modified file 'python/subunit/test_results.py'
--- python/subunit/test_results.py 2012-04-26 13:17:40 +0000
+++ python/subunit/test_results.py 2012-04-28 02:30:27 +0000
@@ -310,7 +310,8 @@
def __init__(self, result, filter_error=False, filter_failure=False,
filter_success=True, filter_skip=False, filter_xfail=False,
- filter_predicate=None, fixup_expected_failures=None):
+ filter_predicate=None, fixup_expected_failures=None,
+ on_filter=None):
"""Create a FilterResult object filtering to result.
:param filter_error: Filter out errors.
@@ -355,6 +356,7 @@
self._fixup_expected_failures = frozenset()
else:
self._fixup_expected_failures = fixup_expected_failures
+ self.on_filter = on_filter
def addError(self, test, err=None, details=None):
if (self.filter_predicate(test, 'error', err, details)):
@@ -365,7 +367,7 @@
self._buffered_calls.append(
('addError', [test, err], {'details': details}))
else:
- self._filtered()
+ self._filtered(test)
def addFailure(self, test, err=None, details=None):
if (self.filter_predicate(test, 'failure', err, details)):
@@ -376,14 +378,14 @@
self._buffered_calls.append(
('addFailure', [test, err], {'details': details}))
else:
- self._filtered()
+ self._filtered(test)
def addSkip(self, test, reason=None, details=None):
if (self.filter_predicate(test, 'skip', reason, details)):
self._buffered_calls.append(
('addSkip', [test, reason], {'details': details}))
else:
- self._filtered()
+ self._filtered(test)
def addSuccess(self, test, details=None):
if (self.filter_predicate(test, 'success', None, details)):
@@ -394,21 +396,23 @@
self._buffered_calls.append(
('addSuccess', [test], {'details': details}))
else:
- self._filtered()
+ self._filtered(test)
def addExpectedFailure(self, test, err=None, details=None):
if self.filter_predicate(test, 'expectedfailure', err, details):
self._buffered_calls.append(
('addExpectedFailure', [test, err], {'details': details}))
else:
- self._filtered()
+ self._filtered(test)
def addUnexpectedSuccess(self, test, details=None):
self._buffered_calls.append(
('addUnexpectedSuccess', [test], {'details': details}))
- def _filtered(self):
+ def _filtered(self, test):
self._current_test_filtered = True
+ if self.on_filter is not None:
+ self.on_filter(test)
def _failure_expected(self, test):
return (test.id() in self._fixup_expected_failures)
=== modified file 'python/subunit/tests/test_subunit_filter.py'
--- python/subunit/tests/test_subunit_filter.py 2012-04-26 13:17:40 +0000
+++ python/subunit/tests/test_subunit_filter.py 2012-04-28 02:30:27 +0000
@@ -202,6 +202,17 @@
('addSkip', foo, {}),
('stopTest', foo), ], result._events)
+ def test_on_filter(self):
+ filtered_result = unittest.TestResult()
+ filtered = []
+ def on_filter(test):
+ filtered.append(test)
+ result_filter = TestResultFilter(
+ filtered_result, filter_failure=True, on_filter=on_filter)
+ self.run_tests(result_filter)
+ self.assertEqual(['passed', 'failed'],
+ [test.id() for test in filtered])
+
def test_suite():
loader = subunit.tests.TestUtil.TestLoader()
Follow ups