From 191213bca2582ed60c92769a8aa8a17cca0432e6 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Tue, 27 Aug 2019 08:33:21 +0000 Subject: [FIX] tests: avoid warning during a setUpClass failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 735ee54 the logs are improved by getting additional informations from the traceback. When the test fails during the setUpClass, the test object received by the getCallerInfo method is not a TestCase instance but an _ErrorHolder. Although they should have the same API, as stated in unittest documentation, the _ErrorHolder does not have a _testMethodName attribute leading to a warning. With this commit, the warning is skipped in that particular case. closes odoo/odoo#36108 Signed-off-by: Xavier Dollé (xdo) --- odoo/modules/module.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'odoo/modules/module.py') diff --git a/odoo/modules/module.py b/odoo/modules/module.py index 220ea048943..61ebadeeb95 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -544,6 +544,8 @@ class OdooTestResult(unittest.result.TestResult): """ # only test case should be executed in odoo, this is only a safe guard + if isinstance(test, unittest.suite._ErrorHolder): + return if not isinstance(test, unittest.TestCase): _logger.warning('%r is not a TestCase' % test) return -- cgit v1.2.3 From 7c219995379c64aa73140b31976ab464a148aafb Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 27 Aug 2019 14:47:47 +0000 Subject: [FIX] core: Correctly handle log_level in odooTestResult Before this commit --log-level had no impact on test logs. We need to check logger "isEnabledFor" before makeRecord since logger will make this check in error,warn,log... dedicated function before making call to _log. We also need to use modules.py runner instead of unittest logger in OdooTestRunner (test will allways be a suite there) closes odoo/odoo#36142 Signed-off-by: Romain Libert (rli) --- odoo/modules/module.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'odoo/modules/module.py') diff --git a/odoo/modules/module.py b/odoo/modules/module.py index 61ebadeeb95..13c1600985e 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -489,8 +489,9 @@ class OdooTestResult(unittest.result.TestResult): # using logger.log makes it difficult to spot-replace findCaller in # order to provide useful location information (the problematic spot # inside the test function), so use lower-level functions instead - record = logger.makeRecord(logger.name, level, fn, lno, msg, args, exc_info, func, extra, sinfo) - logger.handle(record) + if logger.isEnabledFor(level): + record = logger.makeRecord(logger.name, level, fn, lno, msg, args, exc_info, func, extra, sinfo) + logger.handle(record) def getDescription(self, test): if isinstance(test, unittest.TestCase): @@ -573,10 +574,8 @@ class OdooTestRunner(object): start_time = time.perf_counter() test(result) time_taken = time.perf_counter() - start_time - - logger = logging.getLogger(test.__module__) run = result.testsRun - logger.info("Ran %d test%s in %.3fs", run, run != 1 and "s" or "", time_taken) + _logger.info("Ran %d test%s in %.3fs", run, run != 1 and "s" or "", time_taken) return result current_test = None -- cgit v1.2.3