{"id":9150,"library":"odoo-test-helper","title":"Odoo Test Helper","description":"Odoo Test Helper is a Python library providing a toolbox for writing Odoo tests, primarily by facilitating the loading of fake models. This is particularly useful for testing abstract Odoo modules where real record interaction is needed without actual database persistence. Maintained by the Odoo Community Association (OCA), the library is currently at version 2.1.3 and has an infrequent, as-needed release cadence.","status":"active","version":"2.1.3","language":"en","source_language":"en","source_url":"https://github.com/OCA/odoo-test-helper","tags":["odoo","testing","test-helper","fake-models","orm","oca"],"install":[{"cmd":"pip install odoo-test-helper","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.8 or higher.","package":"python","optional":false}],"imports":[{"symbol":"FakeModelLoader","correct":"from odoo_test_helper import FakeModelLoader"},{"note":"Fake models must be imported AFTER calling `cls.loader.backup_registry()` within `setUpClass` to ensure the registry is properly managed. Importing them directly or too early can lead to Odoo registry corruption issues.","wrong":"from odoo.tests import SavepointCase\nfrom odoo_test_helper import FakeModelLoader\nfrom .models import ResPartner # Wrong: Import before backup_registry()","symbol":"Fake Odoo Models (e.g., ResPartner)","correct":"    # In a test method, AFTER backup_registry()\n    from .models import ResPartner"}],"quickstart":{"code":"from odoo.tests import SavepointCase\nfrom odoo_test_helper import FakeModelLoader\n\n# Define your fake models in a file like 'models.py' in the same directory\n# Example models.py content:\n# from odoo import models, fields\n# class ResPartner(models.Model):\n#     _name = 'res.partner'\n#     _description = 'Fake Partner'\n#     name = fields.Char()\n\nclass TestFakeModel(SavepointCase):\n\n    @classmethod\n    def setUpClass(cls):\n        super().setUpClass()\n        cls.loader = FakeModelLoader(cls.env, cls.__module__)\n        cls.loader.backup_registry()\n\n        # IMPORTANT: Import your fake models AFTER backup_registry()\n        from .models import ResPartner # Assuming 'models.py' contains ResPartner\n\n        cls.loader.update_registry((ResPartner,))\n\n        # Now you can use your fake model\n        cls.test_partner = cls.env['res.partner'].create({'name': 'Test Partner'})\n\n    @classmethod\n    def tearDownClass(cls):\n        cls.loader.restore_registry()\n        super().tearDownClass()\n\n    def test_fake_partner_creation(self):\n        self.assertEqual(self.test_partner.name, 'Test Partner')","lang":"python","description":"This quickstart demonstrates how to set up and use a fake Odoo model within a test case. It shows the correct placement for importing fake models (after `backup_registry`) and how to clean up the registry afterwards."},"warnings":[{"fix":"For Odoo 19+, migrate to native Odoo testing mechanisms. Refer to Odoo's official documentation and OCA migration guides for equivalent native patterns.","message":"This library is explicitly not needed for Odoo 19+ versions. Odoo 19 and newer provide native functionality to achieve the same testing goals, rendering `odoo-test-helper` obsolete for these versions.","severity":"breaking","affected_versions":"Odoo 19.0+"},{"fix":"Exercise caution when using in production-critical test suites. Monitor the GitHub repository for updates and be prepared for potential API changes. Consider pinning to a specific version.","message":"The PyPI development status for `odoo-test-helper` is classified as '2 - Pre-Alpha'. This indicates that the project is still under active development, may have an unstable API, and could introduce breaking changes or significant modifications without a full deprecation cycle.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always ensure that `from .models import YourFakeModel` statements for test-specific models are placed after `cls.loader.backup_registry()` to correctly manage the Odoo registry context.","message":"Incorrect import order of fake Odoo models (e.g., `ResPartner` in the example) can lead to Odoo registry corruption or unexpected behavior. Fake models must be imported *after* `cls.loader.backup_registry()` has been called in `setUpClass`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the test environment's user (e.g., `self.env.user`) has the necessary access rights for your fake model, or explicitly create and apply record rules within your test setup.","cause":"When using fake models or testing with a limited test user, the Odoo access rights or record rules might prevent interaction with the model, even if it's a test-only model.","error":"odoo.exceptions.AccessError: You are not allowed to access this document."},{"fix":"Verify that your fake models are correctly passed to `cls.loader.update_registry((YourFakeModel,))` in `setUpClass` and that `restore_registry()` is in `tearDownClass`.","cause":"This typically occurs if a fake model is used without being properly registered with the Odoo environment, or if the `FakeModelLoader`'s `update_registry` was not called or was called incorrectly for the model. It can also happen if `restore_registry()` is called too early.","error":"odoo.exceptions.MissingError: Record does not exist or has been deleted."},{"fix":"Strictly follow the `FakeModelLoader` pattern: `backup_registry()` first, then import fake models and `update_registry()`, and finally `restore_registry()` in `tearDownClass`.","cause":"This error often indicates that the Odoo registry was not properly backed up or restored, or that fake models were imported in an incorrect order relative to the registry operations, leading to an inconsistent state.","error":"KeyError: 'module_to_models' or issues related to Odoo's registry in general."}]}