From ec587297eb9e245db6fe2b6ca1953a5f9bbda27e Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Mon, 4 Nov 2019 08:49:47 +0000 Subject: [IMP] tests: partially backport classCleanups from CPython 3.8 This commit partially backports bpo-24412, which allows the definition of class cleanups (addClassCleanup) and module cleanups (omitted), similar to instance cleanups (addCleanup). This is useful for tests that override unittest's setUpClass and could crash during its execution: If this happens, it is possible that a bunch of crap is left in the database or even worse, the cursor becomes completely fucked; Thanks to the addClassCleanup, we can undo the damage done by the setUpClass. Another benefit is that it is called unconditionally after tearDownClass is called, so it can also be called as a replacement and/or safer tearDownClass. --- odoo/modules/module.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'odoo/modules/module.py') diff --git a/odoo/modules/module.py b/odoo/modules/module.py index 8d0dd5a7091..851395ba280 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -492,7 +492,8 @@ def run_unit_tests(module_name, position='at_install'): :rtype: bool """ global current_test - from odoo.tests.common import TagsSelector # Avoid import loop + # avoid dependency hell + from odoo.tests.common import TagsSelector, OdooSuite current_test = module_name mods = get_test_modules(module_name) threading.currentThread().testing = True @@ -501,7 +502,7 @@ def run_unit_tests(module_name, position='at_install'): r = True for m in mods: tests = unwrap_suite(unittest.TestLoader().loadTestsFromModule(m)) - suite = unittest.TestSuite(t for t in tests if position_tag.check(t) and config_tags.check(t)) + suite = OdooSuite(t for t in tests if position_tag.check(t) and config_tags.check(t)) if suite.countTestCases(): t0 = time.time() -- cgit v1.2.3