From 5b9b410dbd1f08ba44ba342c0f107b7502af29d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 16 Apr 2022 18:30:17 +0200 Subject: [PATCH] Replace test setuptools command by unittest discover issue9215 review389851002 --- setup.py | 4 +--- tests/__init__.py | 8 ++----- tests/{test_party.py => test_module.py} | 28 +++---------------------- tests/test_scenario.py | 22 +++++++++++++++++++ tox.ini | 3 ++- 5 files changed, 30 insertions(+), 35 deletions(-) rename tests/{test_party.py => test_module.py} (93%) create mode 100644 tests/test_scenario.py diff --git a/setup.py b/setup.py index 76f56aee52..a36a44eeb5 100755 --- a/setup.py +++ b/setup.py @@ -142,6 +142,7 @@ setup(name=name, python_requires='>=3.7', install_requires=requires, extras_require={ + 'test': tests_require, 'VIES': ['python-stdnum[SOAP]'], 'phonenumbers': ['phonenumbers'], }, @@ -151,7 +152,4 @@ setup(name=name, [trytond.modules] party = trytond.modules.party """, - test_suite='tests', - test_loader='trytond.test_loader:Loader', - tests_require=tests_require, ) diff --git a/tests/__init__.py b/tests/__init__.py index 45f83d9005..80f92fc36a 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,10 +1,6 @@ # 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: - from trytond.modules.party.tests.test_party import ( - PartyCheckEraseMixin, suite) -except ImportError: - from .test_party import PartyCheckEraseMixin, suite +from .test_module import PartyCheckEraseMixin -__all__ = ['suite', 'PartyCheckEraseMixin'] +__all__ = ['PartyCheckEraseMixin'] diff --git a/tests/test_party.py b/tests/test_module.py similarity index 93% rename from tests/test_party.py rename to tests/test_module.py index 843334c2a5..3a3ee599ef 100644 --- a/tests/test_party.py +++ b/tests/test_module.py @@ -1,6 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import doctest import unittest try: @@ -8,16 +7,13 @@ try: except ImportError: phonenumbers = None -import trytond.tests.test_tryton from trytond.exceptions import UserError from trytond.model.exceptions import AccessError +from trytond.modules.party.party import IDENTIFIER_TYPES from trytond.pool import Pool -from trytond.tests.test_tryton import ( - ModuleTestCase, doctest_checker, doctest_teardown, with_transaction) +from trytond.tests.test_tryton import ModuleTestCase, with_transaction from trytond.transaction import Transaction -from ..party import IDENTIFIER_TYPES - class PartyCheckEraseMixin: @@ -496,22 +492,4 @@ class PartyTestCase(PartyCheckEraseMixin, ModuleTestCase): [('A', 0), ('B', None)]) -def suite(): - suite = trytond.tests.test_tryton.suite() - suite.addTests(unittest.TestLoader().loadTestsFromTestCase(PartyTestCase)) - suite.addTests(doctest.DocFileSuite( - 'scenario_party_replace.rst', - tearDown=doctest_teardown, encoding='utf-8', - checker=doctest_checker, - optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) - suite.addTests(doctest.DocFileSuite( - 'scenario_party_erase.rst', - tearDown=doctest_teardown, encoding='utf-8', - checker=doctest_checker, - optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) - suite.addTests(doctest.DocFileSuite( - 'scenario_party_phone_number.rst', - tearDown=doctest_teardown, encoding='utf-8', - checker=doctest_checker, - optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) - return suite +del ModuleTestCase diff --git a/tests/test_scenario.py b/tests/test_scenario.py new file mode 100644 index 0000000000..c80e682a7f --- /dev/null +++ b/tests/test_scenario.py @@ -0,0 +1,22 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +import doctest +import glob +import os + +from trytond.tests.test_tryton import doctest_checker, doctest_teardown + + +def load_tests(loader, tests, pattern): + cwd = os.getcwd() + try: + os.chdir(os.path.dirname(__file__)) + for scenario in glob.glob('*.rst'): + tests.addTests(doctest.DocFileSuite( + scenario, tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) + finally: + os.chdir(cwd) + return tests diff --git a/tox.ini b/tox.ini index 33c61733f9..0ad0b74373 100644 --- a/tox.ini +++ b/tox.ini @@ -2,8 +2,9 @@ envlist = {py37,py38,py39,py310}-{sqlite,postgresql} [testenv] +extras = test commands = - coverage run --include=.*/party/* setup.py test + coverage run --include=.*/party/* -m unittest discover -s tests coverage report --include=.*/party/* --omit=*/tests/* deps = coverage