{"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.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install odoo-test-helper"],"cli":null},"imports":["from odoo_test_helper import FakeModelLoader","    # In a test method, AFTER backup_registry()\n    from .models import ResPartner"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}