Run doc tests with different globals

Closes #12441
This commit is contained in:
Cédric Krier
2023-07-29 15:11:05 +02:00
parent 98eeb1727a
commit e862ca836a
4 changed files with 18 additions and 6 deletions
@@ -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',
+1
View File
@@ -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
+2
View File
@@ -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()
+14 -5
View File
@@ -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