Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pytest_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def pytest_cmdline_main(config):
raise Exception(
"please provide a database name in the Odoo configuration file"
)
disable_odoo_test_retry()
monkey_patch_resolve_pkg_root_and_module_name()
odoo.service.server.start(preload=[], stop=True)
# odoo.service.server.start() modifies the SIGINT signal by its own
Expand Down Expand Up @@ -201,6 +202,20 @@ def resolve_pkg_root_and_module_name(
_pytest.pathlib.resolve_pkg_root_and_module_name= resolve_pkg_root_and_module_name


def disable_odoo_test_retry():
"""Odoo BaseCase.run method overload TestCase.run and manage
a retry mechanism that breaks using pytest launcher.
Using `pytest-rerunfailures` we can use `--reruns` parameters
if needs equivalent feature, so we remove such overload here.
"""
try:
from odoo.tests import BaseCase
if hasattr(BaseCase, "run"):
del BaseCase.run
except ImportError:
pass


def _find_manifest_path(collection_path: Path) -> Path:
"""Try to locate an Odoo manifest file in the collection path."""
# check if collection_path is an addon directory
Expand Down
6 changes: 6 additions & 0 deletions tests/mock/odoo/odoo/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
from unittest.mock import MagicMock
common = MagicMock()


class BaseCase:

def run(*args, **kwargs):
super().run(*args, **kwargs)
45 changes: 45 additions & 0 deletions tests/test_pytest_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pytest_odoo import (
_find_manifest_path,
monkey_patch_resolve_pkg_root_and_module_name,
disable_odoo_test_retry,
)


Expand Down Expand Up @@ -84,3 +85,47 @@ def test_resolve_pkg_root_and_module_name_namespace_ok(self):
module_name,
"odoo.addons.my_module.tests.test_module"
)

def test_disable_odoo_test_retry(self):
from odoo.tests import BaseCase

original_basecase_run= BaseCase.run

def restore_basecase_run():
BaseCase.run = original_basecase_run

self.addCleanup(restore_basecase_run)

disable_odoo_test_retry()
self.assertFalse(hasattr(BaseCase, "run"))


def test_disable_odoo_test_retry_ignore_run_doesnt_exists(self):
from odoo.tests import BaseCase

original_basecase_run= BaseCase.run

def restore_basecase_run():
BaseCase.run = original_basecase_run

self.addCleanup(restore_basecase_run)

del BaseCase.run

disable_odoo_test_retry()
self.assertFalse(hasattr(BaseCase, "run"))



def test_import_error(self):
from odoo import tests

original_BaseCase = tests.BaseCase

def restore_basecase():
tests.BaseCase = original_BaseCase

self.addCleanup(restore_basecase)

disable_odoo_test_retry()