From 25bb9f4c5b291e932a2b96f4e3418ee4f50f3bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Tue, 20 Jan 2026 10:56:43 -0300 Subject: [PATCH] [FIX] Run tests for modules with auto_install=True (Odoo >= 19.0) In Odoo 19.0+, the behavior of `odoo -i ` changed: it no longer re-installs modules that are already installed in the database. This creates a problem for testing auto-installable modules. Here's the sequence: 1. During database initialization, we install all dependencies of the addons to test using `odoo -i ` 2. Auto-installable modules get automatically installed at this step because their dependencies are now satisfied 3. Later, when we run tests with `odoo -i `, Odoo sees the module is already installed and skips the installation process 4. Since the module installation is skipped, its unit tests are never executed The fix ensures that auto-installable modules are properly excluded during the initial database setup, so they can be explicitly installed (and tested) during the test execution phase. To achieve this, we leverage the newly added `skip-auto-install` parameter for Odoo 19.0+. Fixes #115 --- bin/oca_init_test_database | 28 +++++++++++++++---- .../addons/addon_auto_install/__init__.py | 0 .../addons/addon_auto_install/__manifest__.py | 8 ++++++ .../addon_auto_install/tests/__init__.py | 1 + .../addon_auto_install/tests/test_success.py | 6 ++++ tests/test_success.py | 11 ++++++++ 6 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 tests/data/addons/addon_auto_install/__init__.py create mode 100644 tests/data/addons/addon_auto_install/__manifest__.py create mode 100644 tests/data/addons/addon_auto_install/tests/__init__.py create mode 100644 tests/data/addons/addon_auto_install/tests/test_success.py diff --git a/bin/oca_init_test_database b/bin/oca_init_test_database index 48d3e8a..14ca0e6 100755 --- a/bin/oca_init_test_database +++ b/bin/oca_init_test_database @@ -9,14 +9,32 @@ set -exo pipefail oca_wait_for_postgres +# Identify ODOO_MAJOR version +if [[ "$ODOO_VERSION" =~ ^([0-9]+)\.([0-9]+)$ ]]; then + ODOO_MAJOR="${BASH_REMATCH[1]}" +else + printf 'Invalid ODOO_VERSION format: %s\n' "$ODOO_VERSION" >&2 + exit 1 +fi + +# Select addons to install if [ -n "${INCLUDE}" ]; then ADDONS=$(manifestoo --select-include "${INCLUDE}" --select-exclude "${EXCLUDE}" list-depends --separator=,) else ADDONS=$(manifestoo --select-addons-dir ${ADDONS_DIR} --select-exclude "${EXCLUDE}" list-depends --separator=,) fi -unbuffer $(which odoo) \ - -d ${PGDATABASE} \ - -i ${ADDONS:-base} \ - --http-interface=127.0.0.1 \ - --stop-after-init | oca_checklog_odoo +# Build odoo run parameters +params=( + -d "$PGDATABASE" + -i "$ADDONS" + --http-interface=127.0.0.1 + --stop-after-init +) + +# Add --skip-auto-install for Odoo 19.0 and later +if (( ODOO_MAJOR >= 19 )); then + params+=(--skip-auto-install) +fi + +unbuffer $(which odoo) ${params[@]} | oca_checklog_odoo diff --git a/tests/data/addons/addon_auto_install/__init__.py b/tests/data/addons/addon_auto_install/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/data/addons/addon_auto_install/__manifest__.py b/tests/data/addons/addon_auto_install/__manifest__.py new file mode 100644 index 0000000..5438ea5 --- /dev/null +++ b/tests/data/addons/addon_auto_install/__manifest__.py @@ -0,0 +1,8 @@ +{ + "name": "addon with successful test", + "version": "1.0.0", + "depends": [ + "base", + ], + "auto_install": True, +} diff --git a/tests/data/addons/addon_auto_install/tests/__init__.py b/tests/data/addons/addon_auto_install/tests/__init__.py new file mode 100644 index 0000000..3fec230 --- /dev/null +++ b/tests/data/addons/addon_auto_install/tests/__init__.py @@ -0,0 +1 @@ +from . import test_success diff --git a/tests/data/addons/addon_auto_install/tests/test_success.py b/tests/data/addons/addon_auto_install/tests/test_success.py new file mode 100644 index 0000000..11c05e8 --- /dev/null +++ b/tests/data/addons/addon_auto_install/tests/test_success.py @@ -0,0 +1,6 @@ +from odoo.tests.common import TransactionCase + + +class Test(TransactionCase): + def test_success(self): + pass diff --git a/tests/test_success.py b/tests/test_success.py index d662812..069c623 100644 --- a/tests/test_success.py +++ b/tests/test_success.py @@ -11,3 +11,14 @@ def test_success(): ["oca_run_tests"], cwd=addons_dir, text=True ) assert did_run_test_module(result, "addon_success.tests.test_success") + + +def test_success_auto_install(): + """Test successful test with auto-install.""" + with install_test_addons(["addon_auto_install"]) as addons_dir: + dropdb() + subprocess.check_call(["oca_init_test_database"], cwd=addons_dir) + result = subprocess.check_output( + ["oca_run_tests"], cwd=addons_dir, text=True + ) + assert did_run_test_module(result, "addon_auto_install.tests.test_success")