From ee29cb914700ba780aa361ca7e463c163c5cc778 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Tue, 14 Jan 2020 10:42:13 +0000 Subject: [PATCH] [FIX] tests: make --test-file great again Sort of but not really, this commit fixes a special case in which launching a --test-file of a file with at least two SavepointCases would create a postgresql deadlock and it would be impossible to terminate the Odoo process without sending a SIGKILL or waiting for the lock to timeout. This was introduced at #39368 and happens because of the way that unittests unwraps suites, to keep it short, when it unwraps the custom OdooSuite class internally, it ends up with a vanilla TestSuite with which to run the different test cases, and since #39368 depends on the overrides added to OdooSuite to function, the class cleanups are not triggered at the end of a test class (rollback, cache cleanups, env reset, registry reset, etc.). The fix is to manually unwrap the suite of tests to keep OdooSuite as the suite with which to call the tests, which was already done for --test-enable (although for different reasons, --test-tags?) which is why --test-enable didn't have any problems. This commit also fixes a typo I found on the backport, which meant classCleanups were not being executed if the setUpClass failed, but it had no effect on classCleanups during tearDownClass. Task-ID 2160398 Depends on #43135 closes odoo/odoo#43296 X-original-commit: 7a5ded7d40afc29043d356b5dece0dbe1fbd5ab3 Signed-off-by: Adrian Torres (adt) --- odoo/service/server.py | 6 +++--- odoo/tests/common.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/odoo/service/server.py b/odoo/service/server.py index f95fd020928..cffb6cd4373 100644 --- a/odoo/service/server.py +++ b/odoo/service/server.py @@ -1155,9 +1155,9 @@ def load_test_file_py(registry, test_file): for mod_mod in get_test_modules(mod): mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__', '')) if test_path == mod_path: - suite = OdooSuite() - for t in unittest.TestLoader().loadTestsFromModule(mod_mod): - suite.addTest(t) + tests = odoo.modules.module.unwrap_suite( + unittest.TestLoader().loadTestsFromModule(mod_mod)) + suite = OdooSuite(tests) _logger.log(logging.INFO, 'running tests %s.', mod_mod.__name__) result = odoo.modules.module.OdooTestRunner().run(suite) success = result.wasSuccessful() diff --git a/odoo/tests/common.py b/odoo/tests/common.py index 8fbf8400a0c..f6eec4d2a9a 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -134,7 +134,7 @@ class OdooSuite(unittest.suite.TestSuite): if sys.version_info < (3, 8): # Partial backport of bpo-24412, merged in CPython 3.8 - def _handleClassSetup(self, test, result): + def _handleClassSetUp(self, test, result): previousClass = getattr(result, '_previousTestClass', None) currentClass = test.__class__ if currentClass == previousClass: