summaryrefslogtreecommitdiff
path: root/odoo/modules/loading.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2020-07-28 12:59:54 +0000
committerXavier Morel <xmo@odoo.com>2020-08-19 14:08:21 +0000
commita3ec3229938b122c66c4a3cc859b72726f4874a2 (patch)
tree93ad9de9e02164795176bce0981d70a9bcb4120f /odoo/modules/loading.py
parentc1c43bbe3808c3685e018148b6b6ea242743683c (diff)
[IMP] core: tests reporting
* remove useless OdooTestRunner * don't log results & time per-file, log a module-level tally instead * add number of tests to post-test results * generate a single test suite per module (see note) * use the previous item to split out the at_install test-running in two steps: generating the suite for the module then running that suite, this way for modules which have no test, or for which all tests have been deselected by test tags, we can avoid some of the setup necessary to prepare for running tests but possibly quite expensive (e.g. `setup_models`) Note: single test suite per module I wanted to stop creating a test result for (essentially) every file in the module, however because of the class-level ``addCleanup``, a TestResult can't be reused by independent suites: In order to run class-level cleanup, the test suite checks between tests if the test it's *preparing* to run is in the same class as the last test it ran, and if not applies the class-level cleanup. The problem is that the "previous test class" is stored on the result object, which is never cleaned up, and the "between tests" check is really performed *before each test*. This means when reusing results across suites it will run the class-level cleanup at the end of one suite and immediately at the start of the next, which will cause issues if class-level cleanups are not idempotent (thankfully ``TestTestCursor`` has a non-idempotent ``tearDownClass` which let me discover the error). Possible fixes are: * don't reuse results * clear the relevant states / attributes between suites * put individual suites in a Big Suite for running The latter seems simpler: just create a single suite for the entire odoo-level module instead of creating one suite per test module. Note to the note: the case of nested suite is taken in account, the "end of suite" cleanup only runs at the end of the top-level suite, so technically we don't have to unwrap suites for *that* purpose, we're doing so in order to filter the test cases inside the suites. But maybe we could integrate this feature to the suites themselves... closes odoo/odoo#55185 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'odoo/modules/loading.py')
-rw-r--r--odoo/modules/loading.py51
1 files changed, 38 insertions, 13 deletions
diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py
index dfe315c95d9..515cd4763bb 100644
--- a/odoo/modules/loading.py
+++ b/odoo/modules/loading.py
@@ -248,16 +248,27 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
cr.commit()
updating = tools.config.options['init'] or tools.config.options['update']
+ test_time = test_queries = 0
+ test_results = None
if tools.config.options['test_enable'] and (needs_update or not updating):
env = api.Environment(cr, SUPERUSER_ID, {})
- if not needs_update:
- registry.setup_models(cr)
- # Python tests
- env['ir.http']._clear_routing_map() # force routing map to be rebuilt
- 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)
+ loader = odoo.tests.loader
+ suite = loader.make_suite(module_name, 'at_install')
+ if suite.countTestCases():
+ if not needs_update:
+ registry.setup_models(cr)
+ # Python tests
+ env['ir.http']._clear_routing_map() # force routing map to be rebuilt
+
+ tests_t0, tests_q0 = time.time(), odoo.sql_db.sql_counter
+ test_results = loader.run_suite(suite, module_name)
+ report.update(test_results)
+ test_time = time.time() - tests_t0
+ test_queries = odoo.sql_db.sql_counter - tests_q0
+
+ # tests may have reset the environment
+ env = api.Environment(cr, SUPERUSER_ID, {})
+ module = env['ir.module.module'].browse(module_id)
if needs_update:
processed_modules.append(package.name)
@@ -274,11 +285,25 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
delattr(package, kind)
module.flush()
- _logger.log(module_log_level, "Module %s loaded in %.2fs, %s queries (+%s extra)",
- module_name,
- time.time() - module_t0,
- cr.sql_log_count - module_cursor_query_count,
- odoo.sql_db.sql_counter - module_extra_query_count) # extra queries: testes, notify, any other closed cursor
+ extra_queries = odoo.sql_db.sql_counter - module_extra_query_count - test_queries
+ extras = []
+ if test_queries:
+ extras.append(f'+{test_queries} test')
+ if extra_queries:
+ extras.append(f'+{extra_queries} other')
+ _logger.log(
+ module_log_level, "Module %s loaded in %.2fs%s, %s queries%s",
+ module_name, time.time() - module_t0,
+ f' (incl. {test_time:.2f}s test)' if test_time else '',
+ cr.sql_log_count - module_cursor_query_count,
+ f' ({", ".join(extras)})' if extras else ''
+ )
+ if test_results and not test_results.wasSuccessful():
+ _logger.error(
+ "Module %s: %d failures, %d errors of %d tests",
+ module_name, len(test_results.failures), len(test_results.errors),
+ test_results.testsRun
+ )
_logger.runbot("%s modules loaded in %.2fs, %s queries (+%s extra)",
len(graph),