Allow to add tests in trytond through entry_points

issue6423
review35371002
This commit is contained in:
Nicolas Évrard
2017-10-02 11:38:02 +02:00
parent 74ef322993
commit ba9cbab0de
3 changed files with 37 additions and 7 deletions
+1
View File
@@ -1,3 +1,4 @@
* Allow to add tests through entry points
* Add translated descriptor for Reference field
* Implement alter_type and alter_size for sqlite backend
* Add a maximum size for request
+13
View File
@@ -1,6 +1,12 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
try:
import pkg_resources
except ImportError:
pkg_resources = None
from ..pool import Pool
from .test import *
from .model import *
@@ -201,6 +207,13 @@ def register():
multivalue.register('tests')
if pkg_resources is not None:
entry_points = pkg_resources.iter_entry_points('trytond.tests')
for test_ep in entry_points:
test_module = test_ep.load()
if hasattr(test_module, 'register'):
test_module.register('tests')
def suite():
from .test_tryton import all_suite
+23 -7
View File
@@ -11,6 +11,10 @@ from itertools import chain
import operator
from functools import wraps
import inspect
try:
import pkg_resources
except ImportError:
pkg_resources = None
from lxml import etree
from sql import Table
@@ -629,14 +633,26 @@ def all_suite(modules=None):
Return all tests suite of current module
'''
suite_ = suite()
def add_tests(filename, module_prefix):
if not (filename.startswith('test_') and filename.endswith('.py')):
return
modname = module_prefix + '.' + filename[:-3]
__import__(modname)
module = sys.modules[modname]
suite_.addTest(module.suite())
for fn in os.listdir(os.path.dirname(__file__)):
if fn.startswith('test_') and fn.endswith('.py'):
if modules and fn[:-3] not in modules:
continue
modname = 'trytond.tests.' + fn[:-3]
__import__(modname)
module = module = sys.modules[modname]
suite_.addTest(module.suite())
add_tests(fn, 'trytond.tests')
if pkg_resources is not None:
entry_points = pkg_resources.iter_entry_points('trytond.tests')
for test_entry_point in entry_points:
base_location = os.path.join(
test_entry_point.dist.location,
*test_entry_point.module_name.split('.'))
for fn in os.listdir(base_location):
add_tests(fn, test_entry_point.module_name)
return suite_