Skip to content

Commit a18337f

Browse files
committed
Support Odoo v18.0: disable odoo test retry feature
Odoo reject the support to pytest-odoo: odoo/odoo#184409 we remove the retry feature support from odoo. user that want to retry faillures test can use option from pytest plugin package.
1 parent b599ed6 commit a18337f

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

pytest_odoo.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def pytest_cmdline_main(config):
8888
raise Exception(
8989
"please provide a database name in the Odoo configuration file"
9090
)
91+
disable_odoo_test_retry()
9192
monkey_patch_resolve_pkg_root_and_module_name()
9293
odoo.service.server.start(preload=[], stop=True)
9394
# odoo.service.server.start() modifies the SIGINT signal by its own
@@ -201,6 +202,20 @@ def resolve_pkg_root_and_module_name(
201202
_pytest.pathlib.resolve_pkg_root_and_module_name= resolve_pkg_root_and_module_name
202203

203204

205+
def disable_odoo_test_retry():
206+
"""Odoo BaseCase.run method overload TestCase.run and manage
207+
a retry mechanism that breaks using pytest launcher.
208+
Using `pytest-rerunfailures` we can use `--reruns` parameters
209+
if needs equivalent feature, so we remove such overload here.
210+
"""
211+
try:
212+
from odoo.tests import BaseCase
213+
if hasattr(BaseCase, "run"):
214+
del BaseCase.run
215+
except ImportError:
216+
pass
217+
218+
204219
def _find_manifest_path(collection_path: Path) -> Path:
205220
"""Try to locate an Odoo manifest file in the collection path."""
206221
# check if collection_path is an addon directory
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
from unittest.mock import MagicMock
22
common = MagicMock()
3+
4+
5+
class BaseCase:
6+
7+
def run(*args, **kwargs):
8+
super().run(*args, **kwargs)

tests/test_pytest_odoo.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pytest_odoo import (
88
_find_manifest_path,
99
monkey_patch_resolve_pkg_root_and_module_name,
10+
disable_odoo_test_retry,
1011
)
1112

1213

@@ -84,3 +85,47 @@ def test_resolve_pkg_root_and_module_name_namespace_ok(self):
8485
module_name,
8586
"odoo.addons.my_module.tests.test_module"
8687
)
88+
89+
def test_disable_odoo_test_retry(self):
90+
from odoo.tests import BaseCase
91+
92+
original_basecase_run= BaseCase.run
93+
94+
def restore_basecase_run():
95+
BaseCase.run = original_basecase_run
96+
97+
self.addCleanup(restore_basecase_run)
98+
99+
disable_odoo_test_retry()
100+
self.assertFalse(hasattr(BaseCase, "run"))
101+
102+
103+
def test_disable_odoo_test_retry_ignore_run_doesnt_exists(self):
104+
from odoo.tests import BaseCase
105+
106+
original_basecase_run= BaseCase.run
107+
108+
def restore_basecase_run():
109+
BaseCase.run = original_basecase_run
110+
111+
self.addCleanup(restore_basecase_run)
112+
113+
del BaseCase.run
114+
115+
disable_odoo_test_retry()
116+
self.assertFalse(hasattr(BaseCase, "run"))
117+
118+
119+
120+
def test_import_error(self):
121+
from odoo import tests
122+
123+
original_BaseCase = tests.BaseCase
124+
125+
def restore_basecase():
126+
tests.BaseCase = original_BaseCase
127+
128+
self.addCleanup(restore_basecase)
129+
130+
disable_odoo_test_retry()
131+

0 commit comments

Comments
 (0)