[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:
Jeremy Kersten
2018-08-22 10:08:30 +02:00
parent 2431e2a9ea
commit 1cfaa12012
3 changed files with 5 additions and 6 deletions
-1
View File
@@ -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
-1
View File
@@ -5,4 +5,3 @@ from . import models
from . import controllers
from . import report
from . import wizard
from . import tests
+5 -4
View File
@@ -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."""