~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/TestUtil.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-27 11:48:50 UTC
  • mto: This revision was merged to the branch mainline in revision 6173.
  • Revision ID: v.ladeuil+lp@free.fr-20110927114850-338r2mns0138klv0
Global options respect their hidden attribute

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import sys
20
20
import logging
21
21
import unittest
22
 
import weakref
23
22
 
24
23
from bzrlib import pyutils
25
24
 
67
66
                    test, test.__class__)
68
67
 
69
68
 
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
 
 
88
69
class TestSuite(unittest.TestSuite):
89
70
    """I am an extended TestSuite with a visitor interface.
90
71
    This is primarily to allow filtering of tests - and suites or
101
82
        tests = list(self)
102
83
        tests.reverse()
103
84
        self._tests = []
104
 
        stored_count = 0
105
 
        count_stored_tests = getattr(result, "_count_stored_tests", int)
106
 
        from bzrlib.tests import selftest_debug_flags
107
 
        notify = "uncollected_cases" in selftest_debug_flags
108
85
        while tests:
109
86
            if result.shouldStop:
110
87
                self._tests = reversed(tests)
111
88
                break
112
 
            case = _run_and_collect_case(tests.pop(), result)()
113
 
            new_stored_count = count_stored_tests()
114
 
            if case is not None and isinstance(case, unittest.TestCase):
115
 
                if stored_count == new_stored_count and notify:
116
 
                    # Testcase didn't fail, but somehow is still alive
117
 
                    FailedCollectionCase(case).run(result)
118
 
                    # Adding a new failure so need to reupdate the count
119
 
                    new_stored_count = count_stored_tests()
120
 
                # GZ 2011-09-16: Previously zombied the case at this point by
121
 
                #                clearing the dict as fallback, skip for now.
122
 
            stored_count = new_stored_count
 
89
            tests.pop().run(result)
123
90
        return result
124
91
 
125
92
 
126
 
def _run_and_collect_case(case, res):
127
 
    """Run test case against result and use weakref to drop the refcount"""
128
 
    case.run(res)
129
 
    return weakref.ref(case)
130
 
 
131
 
 
132
93
class TestLoader(unittest.TestLoader):
133
94
    """Custom TestLoader to extend the stock python one."""
134
95