Skip to content

Commit 0eb0398

Browse files
committed
[FIX] test_import_error: really test while raising import error
1 parent e13b04f commit 0eb0398

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pytest_odoo.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import subprocess
1111
import threading
1212
from contextlib import contextmanager
13-
from unittest import mock
13+
from unittest import mock, TestCase
1414
from pathlib import Path
1515
from typing import Optional
1616

@@ -89,6 +89,7 @@ def pytest_cmdline_main(config):
8989
"please provide a database name in the Odoo configuration file"
9090
)
9191
disable_odoo_test_retry()
92+
support_subtest()
9293
monkey_patch_resolve_pkg_root_and_module_name()
9394
odoo.service.server.start(preload=[], stop=True)
9495
# odoo.service.server.start() modifies the SIGINT signal by its own
@@ -215,6 +216,22 @@ def disable_odoo_test_retry():
215216
# Odoo <= 15.0
216217
pass
217218

219+
def support_subtest():
220+
"""Odoo from version 16.0 overwrite TestCase.SubTest context manager
221+
222+
This overwrite assume the usage of OdooTestResult which we are not
223+
using with pytest-odoo. So this restaure unitest SubTest Context manager
224+
"""
225+
try:
226+
from odoo.tests import BaseCase
227+
BaseCase.subTest = TestCase.subTest
228+
229+
from odoo.tests.case import _Outcome
230+
_Outcome.result_supports_subtests = False
231+
except (ImportError, AttributeError):
232+
# Odoo <= 15.0
233+
pass
234+
218235
def _find_manifest_path(collection_path: Path) -> Path:
219236
"""Try to locate an Odoo manifest file in the collection path."""
220237
# check if collection_path is an addon directory

tests/test_pytest_odoo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,6 @@ def restore_basecase():
127127

128128
self.addCleanup(restore_basecase)
129129

130+
del tests.BaseCase
130131
disable_odoo_test_retry()
131132

0 commit comments

Comments
 (0)