Skip to content
Permalink
Browse files

[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
  • Loading branch information
Elkasitu committed Jan 14, 2020
1 parent 33df32f commit 67c277da82e615685a5c3c70a5b2d12505aca381
Showing with 4 additions and 4 deletions.
  1. +3 −3 odoo/service/server.py
  2. +1 −1 odoo/tests/common.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()
@@ -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:

0 comments on commit 67c277d

Please sign in to comment.
You can’t perform that action at this time.