[IMP] server: --test-enable support tests directory without import
Before this commit, if import from tests directory was not in the __init__ file, it was not possible to launch it with --test-file cli. Now we only check in test directory if file exists. This commit closes #26500
This commit is contained in:
@@ -5,7 +5,6 @@ from . import controllers
|
||||
from . import models
|
||||
from . import wizard
|
||||
from . import report
|
||||
from . import tests
|
||||
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
|
||||
@@ -5,4 +5,3 @@ from . import models
|
||||
from . import controllers
|
||||
from . import report
|
||||
from . import wizard
|
||||
from . import tests
|
||||
|
||||
@@ -36,7 +36,8 @@ except ImportError:
|
||||
setproctitle = lambda x: None
|
||||
|
||||
import odoo
|
||||
from odoo.modules.module import run_unit_tests
|
||||
from odoo.modules import get_modules
|
||||
from odoo.modules.module import run_unit_tests, get_test_modules
|
||||
from odoo.modules.registry import Registry
|
||||
from odoo.release import nt_service_name
|
||||
from odoo.tools import config
|
||||
@@ -891,10 +892,9 @@ def _reexec(updated_modules=None):
|
||||
os.execve(sys.executable, args, os.environ)
|
||||
|
||||
def load_test_file_py(registry, test_file):
|
||||
# Locate python module based on its filename and run the tests
|
||||
test_path, _ = os.path.splitext(os.path.abspath(test_file))
|
||||
for mod_name, mod_mod in list(sys.modules.items()):
|
||||
if mod_mod:
|
||||
for mod in [m for m in get_modules() if '/%s/' % m in test_file]:
|
||||
for mod_mod in get_test_modules(mod):
|
||||
mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__', ''))
|
||||
if test_path == mod_path:
|
||||
suite = unittest.TestSuite()
|
||||
@@ -908,6 +908,7 @@ def load_test_file_py(registry, test_file):
|
||||
registry._assertion_report.report_result(success)
|
||||
if not success:
|
||||
_logger.error('%s: at least one error occurred in a test', test_file)
|
||||
return
|
||||
|
||||
def preload_registries(dbnames):
|
||||
""" Preload a registries, possibly run a test file."""
|
||||
|
||||
Reference in New Issue
Block a user