summaryrefslogtreecommitdiff
path: root/openerp/modules
diff options
context:
space:
mode:
authorchm@openerp.com <>2014-03-18 13:22:50 +0100
committerchm@openerp.com <>2014-03-18 13:22:50 +0100
commitbbca8bd17ec4294b21e2f6fc2c62d7a67ef7fab2 (patch)
treec30164859b9ed888e5d463dc19f845092aa8070d /openerp/modules
parent9d026e3fe3fffeef29a1c0cf745499ae082bd79c (diff)
[PATCH] sle
bzr revid: chm@openerp.com-20140318122250-22bt2bcfzvxowkvf
Diffstat (limited to 'openerp/modules')
-rw-r--r--openerp/modules/loading.py8
-rw-r--r--openerp/modules/module.py36
2 files changed, 25 insertions, 19 deletions
diff --git a/openerp/modules/loading.py b/openerp/modules/loading.py
index 681d8534c05..5635e42e780 100644
--- a/openerp/modules/loading.py
+++ b/openerp/modules/loading.py
@@ -42,6 +42,7 @@ from openerp import SUPERUSER_ID
from openerp.tools.translate import _
from openerp.modules.module import initialize_sys_path, \
load_openerp_module, init_module_models, adapt_version
+from module import runs_post_install
_logger = logging.getLogger(__name__)
_test_logger = logging.getLogger('openerp.tests')
@@ -425,8 +426,13 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
for model in registry.models.values():
model._register_hook(cr)
+ # STEP 9: Run the post-install tests
+ cr.commit()
+ if openerp.tools.config['test_enable']:
+ cr.execute("SELECT name FROM ir_module_module WHERE state='installed'")
+ for module_name in cr.fetchall():
+ report.record_result(openerp.modules.module.run_unit_tests(module_name[0], cr.dbname, position=runs_post_install))
finally:
cr.close()
-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
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