odoo-local/docs/Overriding tests.md

37 lines
1.1 KiB
Markdown

# Odoo : Overriding native tests
_Based on information founded [here]( https://www.linkedin.com/pulse/fixing-native-tests-odoo-14-oleh-diatlenko) - Adapted to fit in one file, works in Odoo 15_
## Inheriting the Class
Identify the class with tests to override and declare a class inheriting it, in the `tests` folder of your module
```python
# file : tests/test_to_override.py
# -*- coding: utf-8 -*-
from odoo.addons.module.tests.test_to_override import TestToOverride
from odoo.tests import tagged
@tagged('whatever')
class TestToOverrideInherited(TestToOverride):
def test_function_overriding(self):
#testing
```
## Disable native tests
Even with this system, native tests will still be ran. To disable them, you need to void the functions :
```python
@tagged('whatever')
class TestToOverrideInherited(TestToOverride):
@unittest.skip('Overriden test')
def void(self: TestToOverride):
pass
# disable tests - do not disable a test without writing another one, testing is important!
TestToOverride.test_function_to_override = void
```