summaryrefslogtreecommitdiff
path: root/odoo/modules/loading.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2020-07-28 09:38:14 +0000
committerXavier Morel <xmo@odoo.com>2020-08-19 14:08:12 +0000
commitc1c43bbe3808c3685e018148b6b6ea242743683c (patch)
tree15c9f8a2a29bccb7a1363819614a24b44d421ad8 /odoo/modules/loading.py
parentec8a64a85c7ce751bbd4fc3b5a2a8224a84c81d0 (diff)
[REM] core: assertion reports
That's a not-very-useful subset of OdooTestResult, so: * make results merge-able (aka add ability to update a result with the contents of another) * remove support for test data files, and transmission of the assertion report thing through the data-files loading * replace "legitimate" uses of assertion report by test result * have run_unit_tests manipulate and return a result instead of weird flags & ternaries
Diffstat (limited to 'odoo/modules/loading.py')
-rw-r--r--odoo/modules/loading.py35
1 files changed, 10 insertions, 25 deletions
diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py
index a3adfe8492b..dfe315c95d9 100644
--- a/odoo/modules/loading.py
+++ b/odoo/modules/loading.py
@@ -23,7 +23,7 @@ _logger = logging.getLogger(__name__)
_test_logger = logging.getLogger('odoo.tests')
-def load_data(cr, idref, mode, kind, package, report):
+def load_data(cr, idref, mode, kind, package):
"""
kind: data, demo, test, init_xml, update_xml, demo_xml.
@@ -66,14 +66,14 @@ def load_data(cr, idref, mode, kind, package, report):
noupdate = False
if kind in ('demo', 'demo_xml') or (filename.endswith('.csv') and kind in ('init', 'init_xml')):
noupdate = True
- tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
+ tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind)
finally:
if kind in ('demo', 'test'):
threading.currentThread().testing = False
return bool(filename)
-def load_demo(cr, package, idref, mode, report=None):
+def load_demo(cr, package, idref, mode):
"""
Loads demo data for the specified package.
"""
@@ -83,7 +83,7 @@ def load_demo(cr, package, idref, mode, report=None):
try:
_logger.info("Module %s: loading demo", package.name)
with cr.savepoint(flush=False):
- load_data(cr, idref, mode, kind='demo', package=package, report=report)
+ load_data(cr, idref, mode, kind='demo', package=package)
return True
except Exception as e:
# If we could not install demo data for this module
@@ -129,20 +129,6 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
:param skip_modules: optional list of module names (packages) which have previously been loaded and can be skipped
:return: list of modules that were installed or updated
"""
- def load_test(idref, mode):
- cr.execute("SAVEPOINT load_test_data_file")
- try:
- # return `None` if `load_data` didn't load any file
- return load_data(cr, idref, mode, 'test', package, report) or None
- except Exception:
- _test_logger.exception(
- 'module %s: an exception occurred in a test', package.name)
- return False
- finally:
- cr.execute("ROLLBACK TO SAVEPOINT load_test_data_file")
- # avoid keeping stale xml_id, etc. in cache
- odoo.registry(cr.dbname).clear_caches()
-
if models_to_check is None:
models_to_check = set()
@@ -232,8 +218,8 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
if package.state == 'to upgrade':
# upgrading the module information
module.write(module.get_values_from_terp(package.data))
- load_data(cr, idref, mode, kind='data', package=package, report=report)
- demo_loaded = package.dbdemo = load_demo(cr, package, idref, mode, report)
+ load_data(cr, idref, mode, kind='data', package=package)
+ demo_loaded = package.dbdemo = load_demo(cr, package, idref, mode)
cr.execute('update ir_module_module set demo=%s where id=%s', (demo_loaded, module_id))
module.invalidate_cache(['demo'])
@@ -266,10 +252,9 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
env = api.Environment(cr, SUPERUSER_ID, {})
if not needs_update:
registry.setup_models(cr)
- report.record_result(load_test(idref, mode))
# Python tests
env['ir.http']._clear_routing_map() # force routing map to be rebuilt
- report.record_result(odoo.tests.loader.run_unit_tests(module_name))
+ report.update(odoo.tests.loader.run_unit_tests(module_name))
# tests may have reset the environment
env = api.Environment(cr, SUPERUSER_ID, {})
module = env['ir.module.module'].browse(module_id)
@@ -540,10 +525,10 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
except Exception as e:
_logger.warning('invalid custom view(s) for model %s: %s', model, tools.ustr(e))
- if report.failures:
- _logger.error('At least one test failed when loading the modules.')
- else:
+ if report.wasSuccessful():
_logger.info('Modules loaded.')
+ else:
+ _logger.error('At least one test failed when loading the modules.')
# STEP 8: call _register_hook on every model
env = api.Environment(cr, SUPERUSER_ID, {})