summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odoo/modules/loading.py16
-rw-r--r--odoo/modules/registry.py1
-rw-r--r--odoo/service/server.py21
-rw-r--r--odoo/tests/common.py9
4 files changed, 26 insertions, 21 deletions
diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py
index e9744844841..0f9987f62eb 100644
--- a/odoo/modules/loading.py
+++ b/odoo/modules/loading.py
@@ -19,8 +19,7 @@ import odoo.modules.registry
import odoo.tools as tools
from odoo import api, SUPERUSER_ID
-from odoo.modules.module import adapt_version, initialize_sys_path, \
- load_openerp_module, runs_post_install
+from odoo.modules.module import adapt_version, initialize_sys_path, load_openerp_module
_logger = logging.getLogger(__name__)
_test_logger = logging.getLogger('odoo.tests')
@@ -416,18 +415,9 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
for model in env.values():
model._register_hook()
- # STEP 9: Run the post-install tests
+ # STEP 9: save installed/updated modules for post-install tests
+ registry.updated_modules += processed_modules
cr.commit()
- t0 = time.time()
- t0_sql = odoo.sql_db.sql_counter
- if odoo.tools.config['test_enable']:
- if update_module:
- cr.execute("SELECT name FROM ir_module_module WHERE state='installed' and name = ANY(%s)", (processed_modules,))
- else:
- cr.execute("SELECT name FROM ir_module_module WHERE state='installed'")
- for module_name in cr.fetchall():
- report.record_result(odoo.modules.module.run_unit_tests(module_name[0], cr.dbname, position=runs_post_install))
- _logger.log(25, "All post-tested in %.2fs, %s queries", time.time() - t0, odoo.sql_db.sql_counter - t0_sql)
finally:
cr.close()
diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py
index 6e5378d33c8..7bfacb700fb 100644
--- a/odoo/modules/registry.py
+++ b/odoo/modules/registry.py
@@ -109,6 +109,7 @@ class Registry(Mapping):
# modules fully loaded (maintained during init phase by `loading` module)
self._init_modules = set()
+ self.updated_modules = [] # installed/updated modules
self.db_name = db_name
self._db = odoo.sql_db.db_connect(db_name)
diff --git a/odoo/service/server.py b/odoo/service/server.py
index b44640edbd6..cf1a4cf013d 100644
--- a/odoo/service/server.py
+++ b/odoo/service/server.py
@@ -36,6 +36,7 @@ except ImportError:
setproctitle = lambda x: None
import odoo
+from odoo.modules.module import run_unit_tests, runs_post_install
from odoo.modules.registry import Registry
from odoo.release import nt_service_name
import odoo.tools.config as config
@@ -888,16 +889,16 @@ def load_test_file_py(registry, test_file):
def preload_registries(dbnames):
""" Preload a registries, possibly run a test file."""
# TODO: move all config checks to args dont check tools.config here
- config = odoo.tools.config
- test_file = config['test_file']
dbnames = dbnames or []
rc = 0
for dbname in dbnames:
try:
update_module = config['init'] or config['update']
registry = Registry.new(dbname, update_module=update_module)
+
# run test_file if provided
- if test_file:
+ if config['test_file']:
+ test_file = config['test_file']
_logger.info('loading test file %s', test_file)
with odoo.api.Environment.manage():
if test_file.endswith('yml'):
@@ -905,6 +906,20 @@ def preload_registries(dbnames):
elif test_file.endswith('py'):
load_test_file_py(registry, test_file)
+ # run post-install tests
+ if config['test_enable']:
+ t0 = time.time()
+ t0_sql = odoo.sql_db.sql_counter
+ module_names = (registry.updated_modules if update_module else
+ registry._init_modules)
+ with odoo.api.Environment.manage():
+ for module_name in module_names:
+ result = run_unit_tests(module_name, registry.db_name,
+ position=runs_post_install)
+ registry._assertion_report.record_result(result)
+ _logger.info("All post-tested in %.2fs, %s queries",
+ time.time() - t0, odoo.sql_db.sql_counter - t0_sql)
+
if registry._assertion_report.failures:
rc += 1
except Exception:
diff --git a/odoo/tests/common.py b/odoo/tests/common.py
index 883904cd8c1..c2464864972 100644
--- a/odoo/tests/common.py
+++ b/odoo/tests/common.py
@@ -232,6 +232,7 @@ class RedirectHandler(urllib2.HTTPRedirectHandler):
class HttpCase(TransactionCase):
""" Transactional HTTP TestCase with url_open and phantomjs helpers.
"""
+ registry_test_mode = True
def __init__(self, methodName='runTest'):
super(HttpCase, self).__init__(methodName)
@@ -243,7 +244,9 @@ class HttpCase(TransactionCase):
def setUp(self):
super(HttpCase, self).setUp()
- self.registry.enter_test_mode()
+ if self.registry_test_mode:
+ self.registry.enter_test_mode()
+ self.addCleanup(self.registry.leave_test_mode)
# setup a magic session_id that will be rollbacked
self.session = odoo.http.root.session_store.new()
self.session_id = self.session.sid
@@ -258,10 +261,6 @@ class HttpCase(TransactionCase):
self.opener.add_handler(RedirectHandler())
self.opener.addheaders.append(('Cookie', 'session_id=%s' % self.session_id))
- def tearDown(self):
- self.registry.leave_test_mode()
- super(HttpCase, self).tearDown()
-
def url_open(self, url, data=None, timeout=10):
if url.startswith('/'):
url = "http://%s:%s%s" % (HOST, PORT, url)