summaryrefslogtreecommitdiff
path: root/odoo/tests
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/tests
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/tests')
-rw-r--r--odoo/tests/loader.py14
-rw-r--r--odoo/tests/runner.py15
2 files changed, 20 insertions, 9 deletions
diff --git a/odoo/tests/loader.py b/odoo/tests/loader.py
index c2cc53452fa..99df113a82e 100644
--- a/odoo/tests/loader.py
+++ b/odoo/tests/loader.py
@@ -9,7 +9,7 @@ import unittest
import odoo
from .. import tools
from .common import TagsSelector, OdooSuite
-from .runner import OdooTestRunner
+from .runner import OdooTestRunner, OdooTestResult
# backwards compatibility
_logger = logging.getLogger('odoo.modules.module')
@@ -67,7 +67,8 @@ def run_unit_tests(module_name, position='at_install'):
threading.currentThread().testing = True
config_tags = TagsSelector(tools.config['test_tags'])
position_tag = TagsSelector(position)
- ran_tests = failures = False
+
+ results = OdooTestResult()
for m in mods:
tests = unwrap_suite(unittest.TestLoader().loadTestsFromModule(m))
suite = OdooSuite(t for t in tests if position_tag.check(t) and config_tags.check(t))
@@ -77,23 +78,18 @@ def run_unit_tests(module_name, position='at_install'):
t0_sql = odoo.sql_db.sql_counter
_logger.info('%s running tests.', m.__name__)
result = OdooTestRunner().run(suite)
+ results.update(result)
log_level = logging.INFO
if time.time() - t0 > 5:
log_level = logging.RUNBOT
_logger.log(log_level, "%s ran %s tests in %.2fs, %s queries", m.__name__, result.testsRun, time.time() - t0, odoo.sql_db.sql_counter - t0_sql)
- ran_tests = True
if not result.wasSuccessful():
- failures = True
_logger.error("Module %s: %d failures, %d errors", module_name, len(result.failures), len(result.errors))
module.current_test = None
threading.currentThread().testing = False
- if failures:
- return False
- if ran_tests:
- return True
- return None
+ return results
def unwrap_suite(test):
diff --git a/odoo/tests/runner.py b/odoo/tests/runner.py
index 23e285005bd..132124fe031 100644
--- a/odoo/tests/runner.py
+++ b/odoo/tests/runner.py
@@ -10,6 +10,21 @@ class OdooTestResult(unittest.result.TestResult):
but replacing the "findCaller" in order to give the information we
have based on the test object that is running.
"""
+ def __str__(self):
+ return f'{len(self.failures)} failed, {len(self.errors)} errors of {self.testsRun} tests'
+
+ def update(self, other):
+ """ Merges an other test result into this one, only updates contents
+
+ :type other: OdooTestResult
+ """
+ self.failures.extend(other.failures)
+ self.errors.extend(other.errors)
+ self.testsRun += other.testsRun
+ self.skipped.extend(other.skipped)
+ self.expectedFailures.extend(other.expectedFailures)
+ self.unexpectedSuccesses.extend(other.unexpectedSuccesses)
+ self.shouldStop = self.shouldStop or other.shouldStop
def log(self, level, msg, *args, test=None, exc_info=None, extra=None, stack_info=False, caller_infos=None):
"""