From 29b414891d5a2a1d86b1dcc3958cf73f0f44a9b4 Mon Sep 17 00:00:00 2001 From: Jared Esparza Date: Thu, 28 Apr 2022 11:33:50 +0200 Subject: [PATCH] Replace test setuptools command by unittest discover --- tests/__init__.py | 6 ---- .../{test_party_company.py => test_module.py} | 29 ++++++------------- tests/test_scenario.py | 23 +++++++++++++++ 3 files changed, 32 insertions(+), 26 deletions(-) rename tests/{test_party_company.py => test_module.py} (71%) create mode 100644 tests/test_scenario.py diff --git a/tests/__init__.py b/tests/__init__.py index f2d7ca1..e69de29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +0,0 @@ -# This file is part party_company module for Tryton. -# The COPYRIGHT file at the top level of this repository contains -# the full copyright notices and license terms. -from .test_party_company import suite - -__all__ = ['suite', 'set_company'] diff --git a/tests/test_party_company.py b/tests/test_module.py similarity index 71% rename from tests/test_party_company.py rename to tests/test_module.py index 77a626f..e9a5b79 100644 --- a/tests/test_party_company.py +++ b/tests/test_module.py @@ -1,16 +1,13 @@ -# This file is part party_company module for Tryton. -# The COPYRIGHT file at the top level of this repository contains -# the full copyright notices and license terms. -import unittest -import doctest + +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + from contextlib import contextmanager -import trytond.tests.test_tryton from trytond.tests.test_tryton import ModuleTestCase, with_transaction -from trytond.tests.test_tryton import (doctest_setup, doctest_teardown, - doctest_checker) from trytond.transaction import Transaction from trytond.pool import Pool -from trytond.modules.company.tests import create_company +from trytond.modules.company.tests import CompanyTestMixin, create_company + @contextmanager def set_company(company): @@ -24,8 +21,8 @@ def set_company(company): yield -class PartyCompanyTestCase(ModuleTestCase): - 'Test Party Company module' +class PartyCompanyTestCase(CompanyTestMixin, ModuleTestCase): + 'Test PartyCompany module' module = 'party_company' @with_transaction() @@ -78,12 +75,4 @@ class PartyCompanyTestCase(ModuleTestCase): self.assertEqual(user.companies[1] == company2, True) -def suite(): - suite = trytond.tests.test_tryton.suite() - suite.addTests(unittest.TestLoader().loadTestsFromTestCase( - PartyCompanyTestCase)) - suite.addTests(doctest.DocFileSuite('scenario_party_company.rst', - setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8', - optionflags=doctest.REPORT_ONLY_FIRST_FAILURE, - checker=doctest_checker)) - return suite +del ModuleTestCase diff --git a/tests/test_scenario.py b/tests/test_scenario.py new file mode 100644 index 0000000..b5e24ad --- /dev/null +++ b/tests/test_scenario.py @@ -0,0 +1,23 @@ + +# 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 \ No newline at end of file