diff --git a/cookiecutter-module/{{ cookiecutter.module_name }}/setup.py b/cookiecutter-module/{{ cookiecutter.module_name }}/setup.py index dc6bcb242a..deefb48fed 100755 --- a/cookiecutter-module/{{ cookiecutter.module_name }}/setup.py +++ b/cookiecutter-module/{{ cookiecutter.module_name }}/setup.py @@ -93,7 +93,7 @@ setup(name=name, package_data={ 'trytond.modules.{{ cookiecutter.module_name }}': (info.get('xml', []) + ['tryton.cfg', 'view/*.xml', 'locale/*.po', '*.fodt', - 'icons/*.svg', 'tests/*.rst']), + 'icons/*.svg', 'tests/*.rst', 'tests/*.json']), }, classifiers=[ 'Development Status :: 5 - Production/Stable', diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 3af7b19d4a..9f6cd9a068 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Run doc tests with different globals * Create user applications as validated from user preferences * Support GIN index with btree_gin PostgreSQL extension * Add a canonicalize function for domains diff --git a/trytond/doc/ref/tests.rst b/trytond/doc/ref/tests.rst index 9f7645d21a..c0b4f8f150 100644 --- a/trytond/doc/ref/tests.rst +++ b/trytond/doc/ref/tests.rst @@ -88,6 +88,8 @@ doctest helpers :py:class:`~doctest.DocTest` all ``*.rst`` files in ``directory``, with the module ``name`` and the ``path`` to the module file from which the doc tests are registered. + If a file with the same name but the extension ``.json`` exists, the test is + registered for each globals defined in the JSON list. .. function:: suite() diff --git a/trytond/trytond/tests/test_tryton.py b/trytond/trytond/tests/test_tryton.py index f9c839d564..8efbc72c0d 100644 --- a/trytond/trytond/tests/test_tryton.py +++ b/trytond/trytond/tests/test_tryton.py @@ -4,8 +4,10 @@ import doctest import glob import inspect +import json import operator import os +import pathlib import subprocess import sys import time @@ -1047,11 +1049,18 @@ def load_doc_tests(name, path, loader, tests, pattern): os.chdir(directory) for scenario in filter( shouldIncludeScenario, glob.glob('*.rst')): - tests.addTests(doctest.DocFileSuite( - scenario, package=name, - tearDown=doctest_teardown, encoding='utf-8', - checker=doctest_checker, - optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) + config = pathlib.Path(scenario).with_suffix('.json') + if os.path.exists(config): + with config.open() as fp: + configs = json.load(fp) + else: + configs = [{}] + for globs in configs: + tests.addTests(doctest.DocFileSuite( + scenario, package=name, globs=globs, + tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) finally: os.chdir(cwd) return tests