diff --git a/CHANGELOG b/CHANGELOG index 79d848bbda..a162d5ce3b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/trytond/tests/__init__.py b/trytond/tests/__init__.py index 724f09300e..103e3beb42 100644 --- a/trytond/tests/__init__.py +++ b/trytond/tests/__init__.py @@ -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 diff --git a/trytond/tests/test_tryton.py b/trytond/tests/test_tryton.py index 268b0bbfdc..560eb5673a 100644 --- a/trytond/tests/test_tryton.py +++ b/trytond/tests/test_tryton.py @@ -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_