~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/TestUtil.py

Use pseudo testcase to always fail as suggested by lifeless in review rather than hacking the subunit stream

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
                    test, test.__class__)
68
68
 
69
69
 
 
70
class FailedCollectionCase(unittest.TestCase):
 
71
    """Pseudo-test to run and report failure if given case was uncollected"""
 
72
 
 
73
    def __init__(self, case):
 
74
        super(FailedCollectionCase, self).__init__("fail_uncollected")
 
75
        # GZ 2011-09-16: Maybe catch errors from id() method as cases may be
 
76
        #                in a bit of a funny state by now.
 
77
        self._problem_case_id = case.id()
 
78
 
 
79
    def id(self):
 
80
        if self._problem_case_id[-1:] == ")":
 
81
            return self._problem_case_id[:-1] + ",uncollected)"
 
82
        return self._problem_case_id + "(uncollected)"
 
83
 
 
84
    def fail_uncollected(self):
 
85
        self.fail("Uncollected test case: " + self._problem_case_id)
 
86
 
 
87
 
70
88
class TestSuite(unittest.TestSuite):
71
89
    """I am an extended TestSuite with a visitor interface.
72
90
    This is primarily to allow filtering of tests - and suites or
83
101
        tests = list(self)
84
102
        tests.reverse()
85
103
        self._tests = []
86
 
        stream = getattr(result, "stream", None)
87
 
        # With subunit, not only is stream underscored, but the actual result
88
 
        # object is hidden inside a wrapper decorator, get out the real stream
89
 
        if stream is None:
90
 
            stream = result.decorated._stream
91
104
        stored_count = 0
92
105
        count_stored_tests = getattr(result, "_count_stored_tests", int)
93
106
        from bzrlib.tests import selftest_debug_flags
101
114
            if case is not None and isinstance(case, unittest.TestCase):
102
115
                if stored_count == new_stored_count and notify:
103
116
                    # Testcase didn't fail, but somehow is still alive
104
 
                    stream.write("Uncollected test case: %s\n" % (case.id(),))
 
117
                    FailedCollectionCase(case).run(result)
105
118
                # Zombie the testcase but leave a working stub id method
106
119
                case.__dict__ = {"id": lambda _id=case.id(): _id}
107
120
            stored_count = new_stored_count