diff options
| author | chm@openerp.com <> | 2014-03-18 13:22:50 +0100 |
|---|---|---|
| committer | chm@openerp.com <> | 2014-03-18 13:22:50 +0100 |
| commit | bbca8bd17ec4294b21e2f6fc2c62d7a67ef7fab2 (patch) | |
| tree | c30164859b9ed888e5d463dc19f845092aa8070d /openerp/modules/module.py | |
| parent | 9d026e3fe3fffeef29a1c0cf745499ae082bd79c (diff) | |
[PATCH] sle
bzr revid: chm@openerp.com-20140318122250-22bt2bcfzvxowkvf
Diffstat (limited to 'openerp/modules/module.py')
| -rw-r--r-- | openerp/modules/module.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/openerp/modules/module.py b/openerp/modules/module.py index 8958813baa2..551b7a664b5 100644 --- a/openerp/modules/module.py +++ b/openerp/modules/module.py @@ -356,7 +356,23 @@ class TestStream(object): current_test = None -def run_unit_tests(module_name, dbname): +def runs_at(test, hook, default): + # by default, tests do not run post install + test_runs = getattr(test, hook, default) + + # for a test suite, we're done + if not isinstance(test, unittest.TestCase): + return test_runs + + # otherwise check the current test method to see it's been set to a + # different state + method = getattr(test, test._testMethodName) + return getattr(method, hook, test_runs) + +runs_at_install = functools.partial(runs_at, hook='at_install', default=True) +runs_post_install = functools.partial(runs_at, hook='post_install', default=False) + +def run_unit_tests(module_name, dbname, position=runs_at_install): """ :returns: ``True`` if all of ``module_name``'s tests succeeded, ``False`` if any of them failed. @@ -368,7 +384,7 @@ def run_unit_tests(module_name, dbname): r = True for m in mods: tests = unwrap_suite(unittest2.TestLoader().loadTestsFromModule(m)) - suite = unittest2.TestSuite(itertools.ifilter(runs_at_install, tests)) + suite = unittest2.TestSuite(itertools.ifilter(position, tests)) _logger.info('running %s tests.', m.__name__) result = unittest2.TextTestRunner(verbosity=2, stream=TestStream(m.__name__)).run(suite) @@ -380,22 +396,6 @@ def run_unit_tests(module_name, dbname): current_test = None return r -def runs_at(test, hook, default): - # by default, tests do not run post install - test_runs = getattr(test, hook, default) - - # for a test suite, we're done - if not isinstance(test, unittest.TestCase): - return test_runs - - # otherwise check the current test method to see it's been set to a - # different state - method = getattr(test, test._testMethodName) - return getattr(method, hook, test_runs) - -runs_at_install = functools.partial(runs_at, hook='at_install', default=True) -runs_post_install = functools.partial(runs_at, hook='post_install', default=False) - def unwrap_suite(test): """ Attempts to unpack testsuites (holding suites or cases) in order to |
