~qbzr-dev/qbzr/0.22

« back to all changes in this revision

Viewing changes to lib/tests/__init__.py

  • Committer: Gary van der Merwe
  • Author(s): Vincent Ladeuil
  • Date: 2011-01-27 22:27:15 UTC
  • mfrom: (1344.1.4 trunk)
  • Revision ID: garyvdm@gmail.com-20110127222715-sz1znm55dgzlc770
Allow tests to be run with --parallel=fork.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import os
21
21
import sys
22
 
from bzrlib import trace
 
22
from bzrlib import (
 
23
    tests,
 
24
    trace,
 
25
    )
23
26
 
24
27
try:
25
28
    from PyQt4 import QtGui
26
29
except ImportError:
27
 
    _qt_app = "don't initialize it!"    # fake object to avoid QApplication call
28
 
else:
29
 
    _qt_app = None   # intended to hold global QApplication instance for tests.
 
30
    pass
30
31
 
31
32
 
32
33
def load_tests(basic_tests, module, loader):
33
 
    global _qt_app
34
 
    if _qt_app is None:
35
 
        _qt_app = QtGui.QApplication(sys.argv)
36
 
    
37
34
    testmod_names = [
38
35
        'mock',
39
36
        'test_annotate',
68
65
                raise
69
66
    return basic_tests
70
67
 
71
 
 
72
 
def replace_report_exception(test_case):
73
 
    import bzrlib.plugins.qbzr.lib.trace
74
 
    def report_exception(exc_info=None, type=None, window=None,
75
 
                         ui_mode=False):
76
 
        raise
77
 
    old_report_exception = bzrlib.plugins.qbzr.lib.trace.report_exception
78
 
    bzrlib.plugins.qbzr.lib.trace.report_exception = report_exception
79
 
    
80
 
    def restore_report_exception():
81
 
        bzrlib.plugins.qbzr.lib.trace.report_exception = old_report_exception
82
 
    
83
 
    test_case.addCleanup(restore_report_exception)
84
 
    
 
68
# The application should be initialized only once pre process, but this should
 
69
# be delayed until the first tests is run in a given process, doing it when the
 
70
# tests are loaded is too early and failed for selftest --parallel=fork
 
71
_qt_app = None
 
72
 
 
73
 
 
74
class QTestCase(tests.TestCaseWithTransport):
 
75
 
 
76
    def setUp(self):
 
77
        super(QTestCase, self).setUp()
 
78
        global _qt_app
 
79
        if _qt_app is None:
 
80
            _qt_app = QtGui.QApplication(sys.argv)
 
81
        import bzrlib.plugins.qbzr.lib.trace
 
82
        def report_exception(exc_info=None, type=None, window=None,
 
83
                             ui_mode=False):
 
84
            raise
 
85
        self.overrideAttr(bzrlib.plugins.qbzr.lib.trace, 'report_exception',
 
86
                          report_exception)