Support TEST_PYTHONWARNINGS in doctest

We restore the doctest_setup to setup the python warnings based on
TEST_PYTHONWARNINGS.
This commit is contained in:
Cédric Krier committed 2024-12-15 14:45:15 +01:00
1 parent 0206a17048
commit ee79c18d80
2 files changed
+10 -11

No files matched your search

+1 -9
View File
@@ -140,17 +140,9 @@ doctest helpers
.. function:: doctest_setup
Prepare the run of the `doctest`_ by creating a database and dropping it
beforehand if necessary.
Prepare the run of the doctest_.
This function should be used as the ``setUp`` parameter.
.. deprecated:: 4.2
The ``doctest_setup`` function should not be used anymore to set up
:py:func:`~doctest.DocFileSuite`.
New modules should use :func:`~trytond.tests.tools.activate_modules`
instead.
.. function:: doctest_teardown()
Clean up after the run of the doctest_ by dropping the database.
+9 -2
View File
@@ -1208,11 +1208,17 @@ def drop_create(name=DB_NAME, lang='en'):
def doctest_setup(test):
return drop_create()
if pythonwarnings := os.getenv('TEST_PYTHONWARNINGS'):
cm = warnings.catch_warnings()
cm.__enter__()
test._tryton_cleanup = [(cm.__exit__, cm, None, None, None)]
TestCase.setUpClassWarning(pythonwarnings.split(','))
def doctest_teardown(test):
unittest.mock.patch.stopall()
for cleanup in getattr(test, '_tryton_cleanup', []):
cleanup[0](cleanup[1:])
return drop_db()
@@ -1266,7 +1272,8 @@ def load_doc_tests(name, path, loader, tests, pattern, skips=None):
for globs in configs:
tests.addTests(doctest.DocFileSuite(
scenario, package=name, globs=globs,
tearDown=doctest_teardown, encoding='utf-8',
setUp=doctest_setup, tearDown=doctest_teardown,
encoding='utf-8',
checker=doctest_checker,
optionflags=s_optionflags))
finally: