Example #1
0
class IndicoTestCase(unittest.TestCase, FeatureLoadingObject):

    """
    IndicoTestCase is a normal TestCase on steroids. It allows you to load
    "features" that will empower your test classes
    """

    _requires = []
    _slow = False

    def __init__(self, *args, **kwargs):
        self._benchmark = Benchmark()
        unittest.TestCase.__init__(self, *args, **kwargs)
        FeatureLoadingObject.__init__(self)

    def setUp(self):
        if os.environ.get('INDICO_SKIP_SLOW_TESTS') == '1':
            if self._slow:
                self.skipTest('Slow tests disabled')
            testMethod = getattr(self, self._testMethodName)
            if getattr(testMethod, '_slow', False):
                self.skipTest('Slow tests disabled')
        setLocale('en_GB')
        Logger.removeHandler('smtp')
        clearCache()  # init/clear fossil cache
        self._configFeatures(self)
        self._benchmark.start()

    def tearDown(self):
        self._benchmark.stop()
        self._unconfigFeatures(self)

    @contextlib.contextmanager
    def _context(self, *contexts, **kwargs):
        with ExitStack() as stack:
            res = []
            for ctxname in contexts:
                ctx = contextmanager(getattr(self, '_context_%s' % ctxname))
                res.append(stack.enter_context(ctx(**kwargs)))
            yield res if len(res) > 1 else res[0]

    def run(self, result=None):
        res = super(IndicoTestCase, self).run(result)
        if os.environ.get('INDICO_BENCHMARK_TESTS') == '1':
            self._benchmark.print_result(1, 2.5)
        return res
Example #2
0
class IndicoTestCase(unittest.TestCase, FeatureLoadingObject):
    """
    IndicoTestCase is a normal TestCase on steroids. It allows you to load
    "features" that will empower your test classes
    """

    _requires = []
    _slow = False

    def __init__(self, *args, **kwargs):
        self._benchmark = Benchmark()
        unittest.TestCase.__init__(self, *args, **kwargs)
        FeatureLoadingObject.__init__(self)

    def setUp(self):
        if os.environ.get('INDICO_SKIP_SLOW_TESTS') == '1':
            if self._slow:
                self.skipTest('Slow tests disabled')
            testMethod = getattr(self, self._testMethodName)
            if getattr(testMethod, '_slow', False):
                self.skipTest('Slow tests disabled')
        setLocale('en_GB')
        Logger.removeHandler('smtp')
        clearCache()  # init/clear fossil cache
        self._configFeatures(self)
        self._benchmark.start()

    def tearDown(self):
        self._benchmark.stop()
        self._unconfigFeatures(self)

    @contextlib.contextmanager
    def _context(self, *contexts, **kwargs):
        with ExitStack() as stack:
            res = []
            for ctxname in contexts:
                ctx = contextmanager(getattr(self, '_context_%s' % ctxname))
                res.append(stack.enter_context(ctx(**kwargs)))
            yield res if len(res) > 1 else res[0]

    def run(self, result=None):
        res = super(IndicoTestCase, self).run(result)
        if os.environ.get('INDICO_BENCHMARK_TESTS') == '1':
            self._benchmark.print_result(1, 2.5)
        return res
Example #3
0
 def __init__(self, *args, **kwargs):
     self._benchmark = Benchmark()
     unittest.TestCase.__init__(self, *args, **kwargs)
     FeatureLoadingObject.__init__(self)
Example #4
0
 def __init__(self, *args, **kwargs):
     self._benchmark = Benchmark()
     unittest.TestCase.__init__(self, *args, **kwargs)
     FeatureLoadingObject.__init__(self)