diff --git a/CHANGELOG b/CHANGELOG index d5ade835f5..0e562d2baa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Use unittest discover * Add module tutorial * Test all XML view and SVG icon files are used * Add notification message diff --git a/doc/topics/testing.rst b/doc/topics/testing.rst index 968054c600..0655051f6d 100644 --- a/doc/topics/testing.rst +++ b/doc/topics/testing.rst @@ -42,71 +42,66 @@ module. "Test method" self.assertTrue(True) + del ModuleTestCase -Tests from this modules are found by the function -``trytond.modules.my_module.tests.suite`` which must return a -``unittest.TestSuite`` containing all the module's tests. This function is -called by the Tryton test runner script to gather all the tests. -A typical ``suite()`` function thus looks like this: - -.. code-block:: python - - def suite(): - suite = trytond.tests.test_tryton.suite() - suite.addTests(unittest.TestLoader().loadTestsFromTestCase( - MyModuleTestCase)) - suite.addTests(doctest.DocFileSuite('scenario_my_module.rst', - tearDown=doctest_teardown, encoding='utf-8', - optionflags=doctest.REPORT_ONLY_FIRST_FAILURE, - checker=doctest_checker)) - return suite +.. note:: + The ``ModuleTestCase`` must be deleted to not be discovered by ``unittest`` + as it fails to run without module declaration. .. _doctests: https://docs.python.org/library/doctest.html .. _unittest: https://docs.python.org/library/unittest.html +Running trytond's tests +----------------------- + +You can run a specific test file using ``unittest`` command line like: + +.. code-block:: console + + $ python -m unittest trytond.tests.test_tools + +To run all trytond's tests using discover of ``unittest`` with: + +.. code-block:: console + + $ python -m unittest discover -s trytond.tests + +To run all modules tests: + +.. code-block:: console + + $ python -m unittest discover -s trytond.modules + + Running your module's tests --------------------------- -Tryton provides the script ``trytond/tests/run-tests.py``, just invoke it like -that: +You just need to replace the directory path with the one of your module: .. code-block:: console - $ python -m trytond.tests.run-tests -m my_module + $ python -m unittest discover -s trytond.modules.my_module.tests -Testing trytond +Extending trytond's tests +------------------------- + +Python modules extending ``trytond`` core can define additional classes to +register in ``tests`` module. +Those modules must create an entry point ``trytond.tests`` which defines a +``register`` function to be called with the module name. + +Testing options ~~~~~~~~~~~~~~~ -Extending tests ---------------- +Tryton runs tests against the configured database backend. +You can specify the name of the database to use via the environment variable +``DB_NAME``. +Otherwise it generates a random name. -Python modules extending ``trytond`` core can define additional tests that -should be added to the existing ones. - -Those modules must create an entry point ``trytond.tests``. -Any file in the module path specified by this entry point starting with -``test_`` and ending by ``.py`` will be imported. -Each of those file must define a ``suite()`` function that returns a -``unittest.TestSuite`` that will be included in the ``trytond`` test suite. -If the module from the entry point defines a ``register`` function it will be -called when registering the test-specific models in the -:class:`~trytond.pool.Pool`. - -Running trytond tests ---------------------- - -You should use the script ``trytond/tests/run-tests.py`` by invoking it like -that: - -.. code-block:: console - - $ python -m trytond.tests.run-tests - -You can use a different configuration file to check ``trytond`` against -different backend: - -.. code-block:: console - - $ python -m trytond.tests.run-tests -c +A configuration file can be used by setting its path to the environment +variable ``TRYTOND_CONFIG``. +The tests recreate frequently the database. You can accelerate the creation by +setting a cache directory in ``DB_CACHE`` environment which will be used to +dump and restore initial databases backups. diff --git a/setup.py b/setup.py index 31147b84c2..dddd38c94d 100755 --- a/setup.py +++ b/setup.py @@ -163,6 +163,7 @@ setup(name=name, 'passlib >= 1.7.0', ], extras_require={ + 'test': tests_require, 'PostgreSQL': ['psycopg2 >= 2.7.0'], 'graphviz': ['pydot'], 'Levenshtein': ['python-Levenshtein'], @@ -175,9 +176,6 @@ setup(name=name, }, dependency_links=dependency_links, zip_safe=False, - test_suite='trytond.tests', - test_loader='trytond.test_loader:Loader', - tests_require=tests_require, cmdclass={ 'update_rng': rnc2rng, }, diff --git a/tox.ini b/tox.ini index 62968e476e..410cf79383 100644 --- a/tox.ini +++ b/tox.ini @@ -2,8 +2,9 @@ envlist = {py37,py38,py39,py310}-{sqlite,postgresql} [testenv] +extras = test commands = - coverage run setup.py test + coverage run -m unittest discover -s trytond.tests coverage report --include=./trytond/* --omit=*/tests/* deps = coverage diff --git a/trytond/test_loader.py b/trytond/test_loader.py deleted file mode 100644 index 81d91fcac4..0000000000 --- a/trytond/test_loader.py +++ /dev/null @@ -1,10 +0,0 @@ -# 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 unittest import TestLoader - - -class Loader(TestLoader): - - def loadTestsFromModule(self, module): - return module.suite() diff --git a/trytond/tests/__init__.py b/trytond/tests/__init__.py index 82cdabdebc..34b135f172 100644 --- a/trytond/tests/__init__.py +++ b/trytond/tests/__init__.py @@ -65,8 +65,3 @@ def register(): test_module = test_ep.load() if hasattr(test_module, 'register'): test_module.register('tests') - - -def suite(): - from .test_tryton import all_suite - return all_suite() diff --git a/trytond/tests/run-tests.py b/trytond/tests/run-tests.py deleted file mode 100755 index bafa155b0c..0000000000 --- a/trytond/tests/run-tests.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 -# 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 argparse -import logging -import os -import sys -import time -import unittest - -from trytond.config import config - -if __name__ != '__main__': - raise ImportError('%s can not be imported' % __name__) - -logging.disable(logging.CRITICAL) -parser = argparse.ArgumentParser() -parser.add_argument("-c", "--config", dest="config", - help="specify config file") -parser.add_argument("-f", "--failfast", action="store_true", dest="failfast", - help="Stop the test run on the first error or failure") -parser.add_argument("-m", "--modules", action="store_true", dest="modules", - default=False, help="Run also modules tests") -parser.add_argument("--no-doctest", action="store_false", dest="doctest", - default=True, help="Don't run doctest") -parser.add_argument("-v", action="count", default=0, dest="verbosity", - help="Increase verbosity") -parser.add_argument('tests', metavar='test', nargs='*') -parser.epilog = ('The database name can be specified in the DB_NAME ' - 'environment variable.\n' - "A database dump cache directory can be specified in the DB_CACHE " - "environment variable. Dumps will be used to speed up re-run of tests.") -opt = parser.parse_args() - -config.update_etc(opt.config) - -# Import after application is configured -from trytond import backend # noqa: E402 - -if backend.name == 'sqlite': - database_name = ':memory:' -else: - database_name = 'test_' + str(int(time.time())) -os.environ.setdefault('DB_NAME', database_name) - -from trytond.tests.test_tryton import all_suite, modules_suite # noqa: E402 - -if not opt.modules: - suite = all_suite(opt.tests) -else: - suite = modules_suite(opt.tests, doc=opt.doctest) -result = unittest.TextTestRunner( - verbosity=opt.verbosity, failfast=opt.failfast).run(suite) -sys.exit(not result.wasSuccessful()) diff --git a/trytond/tests/test_access.py b/trytond/tests/test_access.py index cf2c1e1cec..aefab27b34 100644 --- a/trytond/tests/test_access.py +++ b/trytond/tests/test_access.py @@ -1030,20 +1030,4 @@ class ModelFieldAccessWriteTestCase(_ModelFieldAccessTestCase): TestAccess.write([record], {'field2': 'test'}) -def suite(): - suite_ = unittest.TestSuite() - suite_.addTests(unittest.TestLoader( - ).loadTestsFromTestCase(ModelAccessReadTestCase)) - suite_.addTests(unittest.TestLoader( - ).loadTestsFromTestCase(ModelAccessWriteTestCase)) - suite_.addTests(unittest.TestLoader( - ).loadTestsFromTestCase(ModelAccessCreateTestCase)) - suite_.addTests(unittest.TestLoader( - ).loadTestsFromTestCase(ModelAccessDeleteTestCase)) - suite_.addTests(unittest.TestLoader( - ).loadTestsFromTestCase(ModelAccessModelTestCase)) - suite_.addTests(unittest.TestLoader( - ).loadTestsFromTestCase(ModelFieldAccessReadTestCase)) - suite_.addTests(unittest.TestLoader( - ).loadTestsFromTestCase(ModelFieldAccessWriteTestCase)) - return suite_ +del _ModelAccessTestCase, _ModelFieldAccessTestCase diff --git a/trytond/tests/test_backend.py b/trytond/tests/test_backend.py index 2fd7f65911..3bb8376076 100644 --- a/trytond/tests/test_backend.py +++ b/trytond/tests/test_backend.py @@ -171,7 +171,3 @@ class BackendTestCase(unittest.TestCase): cursor.execute(*Select([DateTrunc(type_, date)])) value, = cursor.fetchone() self.assertEqual(str(value), str(result)) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(BackendTestCase) diff --git a/trytond/tests/test_bus.py b/trytond/tests/test_bus.py index 569f2b3aad..0b7cbeac62 100644 --- a/trytond/tests/test_bus.py +++ b/trytond/tests/test_bus.py @@ -139,12 +139,3 @@ class BusTestCase(unittest.TestCase): }, 'channel': 'user:1', }) - - -def suite(): - suite_ = unittest.TestSuite() - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( - MessageQueueTestCase)) - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( - BusTestCase)) - return suite_ diff --git a/trytond/tests/test_cache.py b/trytond/tests/test_cache.py index a19de60131..f3b2825851 100644 --- a/trytond/tests/test_cache.py +++ b/trytond/tests/test_cache.py @@ -286,17 +286,3 @@ class LRUDictTransactionTestCase(unittest.TestCase): self.assertEqual(lru_dict, {}) self.assertEqual(lru_dict.counter, Transaction().counter) - - -def suite(): - func = unittest.TestLoader().loadTestsFromTestCase - suite = unittest.TestSuite() - for testcase in [ - CacheTestCase, - MemoryCacheTestCase, - MemoryCacheChannelTestCase, - LRUDictTestCase, - LRUDictTransactionTestCase, - ]: - suite.addTests(func(testcase)) - return suite diff --git a/trytond/tests/test_copy.py b/trytond/tests/test_copy.py index af59f7b532..4c702406af 100644 --- a/trytond/tests/test_copy.py +++ b/trytond/tests/test_copy.py @@ -315,11 +315,3 @@ class CopyTranslationTestCase(TranslationTestCase): with Transaction().set_context(language=self.other_language): record_copies = Translate.browse(record_copies) self.assertEqual({r.name for r in record_copies}, {"Bar"}) - - -def suite(): - suite_ = unittest.TestSuite() - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(CopyTestCase)) - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( - CopyTranslationTestCase)) - return suite_ diff --git a/trytond/tests/test_descriptors.py b/trytond/tests/test_descriptors.py index f2a4de355a..552d210326 100644 --- a/trytond/tests/test_descriptors.py +++ b/trytond/tests/test_descriptors.py @@ -1,12 +1,10 @@ # 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 from trytond.model import descriptors -def suite(): - suite = unittest.TestSuite() - suite.addTest(doctest.DocTestSuite(descriptors)) - return suite +def load_tests(loader, tests, pattern): + tests.addTest(doctest.DocTestSuite(descriptors)) + return tests diff --git a/trytond/tests/test_exportdata.py b/trytond/tests/test_exportdata.py index b75c008fc7..ce6d9f158e 100644 --- a/trytond/tests/test_exportdata.py +++ b/trytond/tests/test_exportdata.py @@ -404,7 +404,3 @@ class ExportDataTestCase(unittest.TestCase): ExportData.export_data_domain( [('boolean', '=', True)], ['boolean']), [[True]]) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(ExportDataTestCase) diff --git a/trytond/tests/test_field_binary.py b/trytond/tests/test_field_binary.py index b6f213aecf..6a71e1da2a 100644 --- a/trytond/tests/test_field_binary.py +++ b/trytond/tests/test_field_binary.py @@ -202,7 +202,3 @@ class FieldBinaryTestCase(unittest.TestCase): self.assertEqual(binary.binary, None) self.assertEqual(binary.binary_id, None) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldBinaryTestCase) diff --git a/trytond/tests/test_field_boolean.py b/trytond/tests/test_field_boolean.py index f4ac1c4da3..db250d36ec 100644 --- a/trytond/tests/test_field_boolean.py +++ b/trytond/tests/test_field_boolean.py @@ -255,7 +255,3 @@ class FieldBooleanTestCase(unittest.TestCase): }) self.assertEqual(boolean.boolean, True) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldBooleanTestCase) diff --git a/trytond/tests/test_field_char.py b/trytond/tests/test_field_char.py index 06533b1037..7eec01d2d6 100644 --- a/trytond/tests/test_field_char.py +++ b/trytond/tests/test_field_char.py @@ -673,13 +673,3 @@ class FieldCharSimilarityTestCase(ExtensionTestCase): "Test order translated" pool = Pool() self._test_order(pool.get('test.char_translate')) - - -def suite(): - suite_ = unittest.TestSuite() - loader = unittest.TestLoader() - suite_.addTests(loader.loadTestsFromTestCase(FieldCharTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(FieldCharTranslatedTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(FieldCharUnaccentedTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(FieldCharSimilarityTestCase)) - return suite_ diff --git a/trytond/tests/test_field_context.py b/trytond/tests/test_field_context.py index d373e91ab9..1fbdab4316 100644 --- a/trytond/tests/test_field_context.py +++ b/trytond/tests/test_field_context.py @@ -30,11 +30,3 @@ class FieldContextTestCase(unittest.TestCase): parent.save() self.assertEqual(parent.child._context['name'], 'bar') self.assertEqual(parent.child._context['rec_name'], '') - - -def suite(): - func = unittest.TestLoader().loadTestsFromTestCase - suite = unittest.TestSuite() - for testcase in (FieldContextTestCase,): - suite.addTests(func(testcase)) - return suite diff --git a/trytond/tests/test_field_date.py b/trytond/tests/test_field_date.py index c52fb94fe6..294eb50a20 100644 --- a/trytond/tests/test_field_date.py +++ b/trytond/tests/test_field_date.py @@ -470,7 +470,3 @@ class FieldDateTestCase(unittest.TestCase): result, = cursor.fetchone() self.assertEqual(result, datetime.date(2021, 10, 15)) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldDateTestCase) diff --git a/trytond/tests/test_field_datetime.py b/trytond/tests/test_field_datetime.py index a05ad30f5d..a73589e9b5 100644 --- a/trytond/tests/test_field_datetime.py +++ b/trytond/tests/test_field_datetime.py @@ -487,7 +487,3 @@ class FieldDateTimeTestCase(unittest.TestCase): DateTime.write([datetime_], { 'datetime': datetime.date(2009, 1, 1), }) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldDateTimeTestCase) diff --git a/trytond/tests/test_field_depends.py b/trytond/tests/test_field_depends.py index d7f7ca5809..fb4d919c6e 100644 --- a/trytond/tests/test_field_depends.py +++ b/trytond/tests/test_field_depends.py @@ -263,7 +263,3 @@ class FieldDependsTestCase(unittest.TestCase): ]: with self.subTest(value=value): self.assertEqual(fields.get_eval_fields(value), result) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldDependsTestCase) diff --git a/trytond/tests/test_field_dict.py b/trytond/tests/test_field_dict.py index 65de75fb2d..d9e6c1e654 100644 --- a/trytond/tests/test_field_dict.py +++ b/trytond/tests/test_field_dict.py @@ -928,7 +928,3 @@ class FieldDictUnaccentedTestCase(ExtensionTestCase): ]) self.assertListEqual(dicts, [dict_]) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldDictTestCase) diff --git a/trytond/tests/test_field_float.py b/trytond/tests/test_field_float.py index 9ecd04d35b..9bbb01daee 100644 --- a/trytond/tests/test_field_float.py +++ b/trytond/tests/test_field_float.py @@ -455,7 +455,3 @@ class FieldFloatTestCase(unittest.TestCase): Float.write([float_], { 'digits': 0, }) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldFloatTestCase) diff --git a/trytond/tests/test_field_function.py b/trytond/tests/test_field_function.py index dd59b6bc27..da6296bb51 100644 --- a/trytond/tests/test_field_function.py +++ b/trytond/tests/test_field_function.py @@ -86,7 +86,3 @@ class FieldFunctionTestCase(unittest.TestCase): Model.read([record.id], ['function1', 'function2']) self.assertEqual(getter.call_count, 1) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldFunctionTestCase) diff --git a/trytond/tests/test_field_integer.py b/trytond/tests/test_field_integer.py index ff7285fe55..aefefa45d2 100644 --- a/trytond/tests/test_field_integer.py +++ b/trytond/tests/test_field_integer.py @@ -344,7 +344,3 @@ class FieldIntegerTestCase(unittest.TestCase): Integer.write([integer], { 'integer': 'non integer', }) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldIntegerTestCase) diff --git a/trytond/tests/test_field_many2many.py b/trytond/tests/test_field_many2many.py index 84f8ebec5f..b254b4aab7 100644 --- a/trytond/tests/test_field_many2many.py +++ b/trytond/tests/test_field_many2many.py @@ -724,12 +724,3 @@ class FieldMany2ManyReferenceTestCase(unittest.TestCase, CommonTestCaseMixin): def Many2ManyTarget(self): return Pool().get('test.many2many_reference.target') - - -def suite(): - suite_ = unittest.TestSuite() - loader = unittest.TestLoader() - suite_.addTests(loader.loadTestsFromTestCase(FieldMany2ManyTestCase)) - suite_.addTests( - loader.loadTestsFromTestCase(FieldMany2ManyReferenceTestCase)) - return suite_ diff --git a/trytond/tests/test_field_many2one.py b/trytond/tests/test_field_many2one.py index daebe41bfd..f10997f3df 100644 --- a/trytond/tests/test_field_many2one.py +++ b/trytond/tests/test_field_many2one.py @@ -431,13 +431,3 @@ class FieldMany2OneMPTTTestCase(FieldMany2OneTreeTestCase): class FieldMany2OnePathTestCase(FieldMany2OneTreeTestCase): "Test Field Many2One Path" model_name = 'test.many2one_path' - - -def suite(): - suite_ = unittest.TestSuite() - loader = unittest.TestLoader() - suite_.addTests(loader.loadTestsFromTestCase(FieldMany2OneTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(FieldMany2OneTreeTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(FieldMany2OneMPTTTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(FieldMany2OnePathTestCase)) - return suite_ diff --git a/trytond/tests/test_field_multiselection.py b/trytond/tests/test_field_multiselection.py index c0245f6f61..11b77997af 100644 --- a/trytond/tests/test_field_multiselection.py +++ b/trytond/tests/test_field_multiselection.py @@ -345,12 +345,3 @@ class FieldMultiSelectionJSONBTestCase(FieldMultiSelectionTestCase): 'ALTER COLUMN %s TYPE json USING %s::json' % ( Model._table, name, name)) Transaction().commit() - - -def suite(): - func = unittest.TestLoader().loadTestsFromTestCase - suite = unittest.TestSuite() - for testcase in [FieldMultiSelectionTestCase, - FieldMultiSelectionJSONBTestCase]: - suite.addTests(func(testcase)) - return suite diff --git a/trytond/tests/test_field_numeric.py b/trytond/tests/test_field_numeric.py index 822a2d1c8a..7af9a2bcbc 100644 --- a/trytond/tests/test_field_numeric.py +++ b/trytond/tests/test_field_numeric.py @@ -526,7 +526,3 @@ class FieldNumericTestCase(unittest.TestCase): Numeric.write([numeric], { 'digits': 0, }) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldNumericTestCase) diff --git a/trytond/tests/test_field_one2many.py b/trytond/tests/test_field_one2many.py index 9566a89662..48c382b9b9 100644 --- a/trytond/tests/test_field_one2many.py +++ b/trytond/tests/test_field_one2many.py @@ -630,12 +630,3 @@ class FieldOne2ManyReferenceTestCase(unittest.TestCase, CommonTestCaseMixin): def One2ManyTarget(self): return Pool().get('test.one2many_reference.target') - - -def suite(): - suite_ = unittest.TestSuite() - loader = unittest.TestLoader() - suite_.addTests(loader.loadTestsFromTestCase(FieldOne2ManyTestCase)) - suite_.addTests( - loader.loadTestsFromTestCase(FieldOne2ManyReferenceTestCase)) - return suite_ diff --git a/trytond/tests/test_field_one2one.py b/trytond/tests/test_field_one2one.py index d54408af9f..6318a2177b 100644 --- a/trytond/tests/test_field_one2one.py +++ b/trytond/tests/test_field_one2one.py @@ -317,7 +317,3 @@ class FieldOne2OneTestCase(unittest.TestCase): One2One.write([one2one2], { 'one2one': target.id, }) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldOne2OneTestCase) diff --git a/trytond/tests/test_field_reference.py b/trytond/tests/test_field_reference.py index a1ab36afe6..83d0d368ef 100644 --- a/trytond/tests/test_field_reference.py +++ b/trytond/tests/test_field_reference.py @@ -524,7 +524,3 @@ class FieldReferenceTestCase(unittest.TestCase): 'reference': str(target), }]) self.assertEqual(reference.reference, target) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldReferenceTestCase) diff --git a/trytond/tests/test_field_selection.py b/trytond/tests/test_field_selection.py index 6ff5647875..898d82f800 100644 --- a/trytond/tests/test_field_selection.py +++ b/trytond/tests/test_field_selection.py @@ -242,7 +242,3 @@ class FieldSelectionTestCase(unittest.TestCase): }]) self.assertEqual(selection.dyn_select_static_string, '1') - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldSelectionTestCase) diff --git a/trytond/tests/test_field_text.py b/trytond/tests/test_field_text.py index bae9038a38..b24a5cc948 100644 --- a/trytond/tests/test_field_text.py +++ b/trytond/tests/test_field_text.py @@ -653,12 +653,3 @@ class FieldFullTextTestCase(unittest.TestCase): self.assertListEqual( Model.search([], order=[('full_text', 'DESC')]), [fat_cat, sad_cat, dog]) - - -def suite(): - suite_ = unittest.TestSuite() - loader = unittest.TestLoader() - suite_.addTests(loader.loadTestsFromTestCase(FieldTextTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(FieldTextTranslatedTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(FieldFullTextTestCase)) - return suite_ diff --git a/trytond/tests/test_field_time.py b/trytond/tests/test_field_time.py index 45c0952d2f..be69e6b4da 100644 --- a/trytond/tests/test_field_time.py +++ b/trytond/tests/test_field_time.py @@ -485,7 +485,3 @@ class FieldTimeTestCase(unittest.TestCase): Time.write([time], { 'time': datetime.date(2009, 1, 1), }) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldTimeTestCase) diff --git a/trytond/tests/test_field_timedelta.py b/trytond/tests/test_field_timedelta.py index 83a5888122..765878d3bb 100644 --- a/trytond/tests/test_field_timedelta.py +++ b/trytond/tests/test_field_timedelta.py @@ -475,7 +475,3 @@ class FieldTimeDeltaTestCase(unittest.TestCase): self.assertEqual( timedelta.timedelta, datetime.timedelta(seconds=42.5)) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FieldTimeDeltaTestCase) diff --git a/trytond/tests/test_filestore.py b/trytond/tests/test_filestore.py index 49851b0a90..4d551bb6de 100644 --- a/trytond/tests/test_filestore.py +++ b/trytond/tests/test_filestore.py @@ -94,7 +94,3 @@ class FileStoreTestCase(unittest.TestCase): self.assertNotEqual(id1, id2) self.assertEqual(filestore.get(id1, prefix='test'), data1) self.assertEqual(filestore.get(id2, prefix='test'), data2) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FileStoreTestCase) diff --git a/trytond/tests/test_history.py b/trytond/tests/test_history.py index a8130cc1c3..c71f6a8f21 100644 --- a/trytond/tests/test_history.py +++ b/trytond/tests/test_history.py @@ -497,7 +497,3 @@ class HistoryTestCase(unittest.TestCase): self.assertEqual({r.value for r in records}, {1}) self.assertEqual(len(records), n) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(HistoryTestCase) diff --git a/trytond/tests/test_i18n.py b/trytond/tests/test_i18n.py index 5701e3998f..ae02c13002 100644 --- a/trytond/tests/test_i18n.py +++ b/trytond/tests/test_i18n.py @@ -106,10 +106,3 @@ class I18nTestCase(unittest.TestCase): self.assertIsInstance(lazy, LazyString) self.assertEqual(str(lazy), "Message") - - -def suite(): - suite = unittest.TestSuite() - loader = unittest.TestLoader() - suite.addTests(loader.loadTestsFromTestCase(I18nTestCase)) - return suite diff --git a/trytond/tests/test_importdata.py b/trytond/tests/test_importdata.py index 0056ed0e71..1f0ef93506 100644 --- a/trytond/tests/test_importdata.py +++ b/trytond/tests/test_importdata.py @@ -586,7 +586,3 @@ class ImportDataTestCase(unittest.TestCase): self.assertEqual(count, 1) self.assertEqual(len(record.one2many), 2) self.assertEqual([t.name for t in record.one2many], ["bar", "baz"]) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(ImportDataTestCase) diff --git a/trytond/tests/test_ir.py b/trytond/tests/test_ir.py index d56716b867..6578b22046 100644 --- a/trytond/tests/test_ir.py +++ b/trytond/tests/test_ir.py @@ -1,7 +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. import datetime -import unittest from decimal import Decimal from unittest.mock import ANY, Mock, patch @@ -384,5 +383,4 @@ class IrTestCase(ModuleTestCase): }) -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(IrTestCase) +del ModuleTestCase diff --git a/trytond/tests/test_mixins.py b/trytond/tests/test_mixins.py index 80745bb298..b2bbdee660 100644 --- a/trytond/tests/test_mixins.py +++ b/trytond/tests/test_mixins.py @@ -146,11 +146,3 @@ class DeactivableMixinTestCase(unittest.TestCase): ([('active', 'in', [True, False])], [active, inactive]), ]: self.assertListEqual(Deactivable.search(domain), founds) - - -def suite(): - func = unittest.TestLoader().loadTestsFromTestCase - suite = unittest.TestSuite() - for testcase in [UrlTestCase, MixinTestCase, DeactivableMixinTestCase]: - suite.addTests(func(testcase)) - return suite diff --git a/trytond/tests/test_model.py b/trytond/tests/test_model.py index 357f15e99e..22cf3f02cc 100644 --- a/trytond/tests/test_model.py +++ b/trytond/tests/test_model.py @@ -415,15 +415,3 @@ class RecordTestCase(unittest.TestCase): rec = Record(foo='baz') self.assertEqual(list(rec._values()), [('baz')]) - - -def suite(): - func = unittest.TestLoader().loadTestsFromTestCase - suite_ = unittest.TestSuite() - for testcase in [ - ModelTestCase, - ModelTranslationTestCase, - RecordTestCase, - ]: - suite_.addTests(func(testcase)) - return suite_ diff --git a/trytond/tests/test_modelsingleton.py b/trytond/tests/test_modelsingleton.py index edcee97b83..d7bb539a13 100644 --- a/trytond/tests/test_modelsingleton.py +++ b/trytond/tests/test_modelsingleton.py @@ -147,7 +147,3 @@ class ModelSingletonTestCase(unittest.TestCase): Singleton.delete([singleton]) self.assertEqual(singleton2.name, 'test') - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(ModelSingletonTestCase) diff --git a/trytond/tests/test_modelsql.py b/trytond/tests/test_modelsql.py index 01165d92a2..63116a2fb4 100644 --- a/trytond/tests/test_modelsql.py +++ b/trytond/tests/test_modelsql.py @@ -1350,12 +1350,3 @@ class ModelSQLTranslationTestCase(TranslationTestCase): self.assertIn(record.id, cache) self.assertEqual(cache[record.id]['name'], "Foo") self.assertNotIn('_timestamp', cache[record.id]) - - -def suite(): - suite_ = unittest.TestSuite() - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( - ModelSQLTestCase)) - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( - ModelSQLTranslationTestCase)) - return suite_ diff --git a/trytond/tests/test_modelstorage.py b/trytond/tests/test_modelstorage.py index c351cfa178..bdd22d3cb8 100644 --- a/trytond/tests/test_modelstorage.py +++ b/trytond/tests/test_modelstorage.py @@ -794,11 +794,3 @@ class EvalEnvironmentTestCase(unittest.TestCase): record = Model(record.id) self.assertEqual(record.name, "Test") - - -def suite(): - suite_ = unittest.TestSuite() - loader = unittest.TestLoader() - suite_.addTests(loader.loadTestsFromTestCase(ModelStorageTestCase)) - suite_.addTests(loader.loadTestsFromTestCase(EvalEnvironmentTestCase)) - return suite_ diff --git a/trytond/tests/test_modelview.py b/trytond/tests/test_modelview.py index 2c9713d67e..31faf2f3f8 100644 --- a/trytond/tests/test_modelview.py +++ b/trytond/tests/test_modelview.py @@ -689,11 +689,3 @@ class ModelView(unittest.TestCase): self.assertIn('bar', writeable_fields) self.assertIn('baz', writeable_fields) self.assertIn('quux', writeable_fields) - - -def suite(): - func = unittest.TestLoader().loadTestsFromTestCase - suite = unittest.TestSuite() - for testcase in (ModelView,): - suite.addTests(func(testcase)) - return suite diff --git a/trytond/tests/test_mptt.py b/trytond/tests/test_mptt.py index 14725d31fc..d4ae314726 100644 --- a/trytond/tests/test_mptt.py +++ b/trytond/tests/test_mptt.py @@ -95,7 +95,3 @@ class MPTTTestCase(TreeTestCaseMixin, unittest.TestCase): }])], }]) self.check_tree() - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(MPTTTestCase) diff --git a/trytond/tests/test_multivalue.py b/trytond/tests/test_multivalue.py index 7554bbdda8..a88a48ecf4 100644 --- a/trytond/tests/test_multivalue.py +++ b/trytond/tests/test_multivalue.py @@ -156,7 +156,3 @@ class MultiValueTestCase(unittest.TestCase): read, = ModelMultiValue.read([record.id], ['value']) self.assertEqual(read['value'], "getter") - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(MultiValueTestCase) diff --git a/trytond/tests/test_order.py b/trytond/tests/test_order.py index a0ea8ccb15..c7894d5325 100644 --- a/trytond/tests/test_order.py +++ b/trytond/tests/test_order.py @@ -32,8 +32,3 @@ class SequenceOrderedMixinTestCase(unittest.TestCase): models.insert(0, model) self.assertListEqual(Order.search([]), models) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase( - SequenceOrderedMixinTestCase) diff --git a/trytond/tests/test_path.py b/trytond/tests/test_path.py index 03618950d1..fb533bc101 100644 --- a/trytond/tests/test_path.py +++ b/trytond/tests/test_path.py @@ -32,7 +32,3 @@ class PathTestCase(TreeTestCaseMixin, unittest.TestCase): pool = Pool() Path = pool.get(self.model_name) Path._rebuild_path('parent') - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(PathTestCase) diff --git a/trytond/tests/test_protocols.py b/trytond/tests/test_protocols.py index ae7734a635..f157c74020 100644 --- a/trytond/tests/test_protocols.py +++ b/trytond/tests/test_protocols.py @@ -118,10 +118,3 @@ class XMLTestCase(DumpsLoadsMixin, unittest.TestCase): result, _ = client.loads(s) result, = result self.assertEqual(result, Decimal('3.141592653589793')) - - -def suite(): - suite_ = unittest.TestSuite() - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(JSONTestCase)) - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(XMLTestCase)) - return suite_ diff --git a/trytond/tests/test_pyson.py b/trytond/tests/test_pyson.py index f41334e496..3a59a712f6 100644 --- a/trytond/tests/test_pyson.py +++ b/trytond/tests/test_pyson.py @@ -870,7 +870,3 @@ class PYSONTestCase(unittest.TestCase): def test_eval_false(self): "Test PYSON.eval JS false" self.assertEqual(eval('false', pyson.CONTEXT), False) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(PYSONTestCase) diff --git a/trytond/tests/test_report.py b/trytond/tests/test_report.py index e2351658e9..d76068576c 100644 --- a/trytond/tests/test_report.py +++ b/trytond/tests/test_report.py @@ -59,10 +59,3 @@ for i, (in_, out) in enumerate([ ]): test_method = create_test_format_timedelta(i, in_, out) setattr(ReportTestCase, test_method.__name__, test_method) - - -def suite(): - suite = unittest.TestSuite() - loader = unittest.TestLoader() - suite.addTests(loader.loadTestsFromTestCase(ReportTestCase)) - return suite diff --git a/trytond/tests/test_res.py b/trytond/tests/test_res.py index 776cf96457..940bf003cb 100644 --- a/trytond/tests/test_res.py +++ b/trytond/tests/test_res.py @@ -85,5 +85,4 @@ class ResTestCase(ModuleTestCase): self.assertFalse(Warning_.check('test')) -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(ResTestCase) +del ModuleTestCase diff --git a/trytond/tests/test_resource.py b/trytond/tests/test_resource.py index 8cbacde41c..4c2c51e6ac 100644 --- a/trytond/tests/test_resource.py +++ b/trytond/tests/test_resource.py @@ -78,7 +78,3 @@ class ResourceTestCase(unittest.TestCase): note = Note(note.id) self.assertEqual(user_note.write_date, write_date) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(ResourceTestCase) diff --git a/trytond/tests/test_routes.py b/trytond/tests/test_routes.py index 03507d1d3d..59b491e1f8 100644 --- a/trytond/tests/test_routes.py +++ b/trytond/tests/test_routes.py @@ -195,7 +195,3 @@ class RoutesTestCase(unittest.TestCase): self.assertEqual(response_std.status_code, 200) self.assertEqual(response_locale.status_code, 200) self.assertNotEqual(response_std.data, response_locale.data) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(RoutesTestCase) diff --git a/trytond/tests/test_rpc.py b/trytond/tests/test_rpc.py index 070ae854a9..48e6b46a8d 100644 --- a/trytond/tests/test_rpc.py +++ b/trytond/tests/test_rpc.py @@ -141,7 +141,3 @@ class RPCTestCase(unittest.TestCase): self.assertEqual( rpc_with_access.convert(None, {}), ([], {}, {'_check_access': True}, None)) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(RPCTestCase) diff --git a/trytond/tests/test_rule.py b/trytond/tests/test_rule.py index c31f5c06ae..a44633d273 100644 --- a/trytond/tests/test_rule.py +++ b/trytond/tests/test_rule.py @@ -681,10 +681,3 @@ class ModelRuleTestCase(unittest.TestCase): with self.assertRaisesRegex(AccessError, "Field different from foo"): TestRuleModel.read([test.id], ['name']) - - -def suite(): - suite_ = unittest.TestSuite() - suite_.addTests( - unittest.TestLoader().loadTestsFromTestCase(ModelRuleTestCase)) - return suite_ diff --git a/trytond/tests/test_sendmail.py b/trytond/tests/test_sendmail.py index 77d3e576cd..33ff943d45 100644 --- a/trytond/tests/test_sendmail.py +++ b/trytond/tests/test_sendmail.py @@ -112,7 +112,3 @@ class SendmailTestCase(unittest.TestCase): server.sendmail.assert_not_called() self.assertFalse(datamanager.queue) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(SendmailTestCase) diff --git a/trytond/tests/test_sequence.py b/trytond/tests/test_sequence.py index 9b55e780cd..87f405643f 100644 --- a/trytond/tests/test_sequence.py +++ b/trytond/tests/test_sequence.py @@ -149,12 +149,3 @@ class SequenceStrictTestCase(SequenceTestCase): def get_model(): pool = Pool() return pool.get('ir.sequence.strict') - - -def suite(): - suite_ = unittest.TestSuite() - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( - SequenceTestCase)) - suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( - SequenceStrictTestCase)) - return suite_ diff --git a/trytond/tests/test_tools.py b/trytond/tests/test_tools.py index 3ea68a8481..14d6ef985e 100644 --- a/trytond/tests/test_tools.py +++ b/trytond/tests/test_tools.py @@ -975,13 +975,6 @@ class DomainInversionTestCase(unittest.TestCase): self.assertEqual(extract_reference_models(domain, 'y'), set()) -def suite(): - func = unittest.TestLoader().loadTestsFromTestCase - suite = unittest.TestSuite() - for testcase in [ToolsTestCase, - StringPartitionedTestCase, - ImmutableDictTestCase, - DomainInversionTestCase]: - suite.addTests(func(testcase)) - suite.addTest(doctest.DocTestSuite(decimal_)) - return suite +def load_tests(loader, tests, pattern): + tests.addTest(doctest.DocTestSuite(decimal_)) + return tests diff --git a/trytond/tests/test_transaction.py b/trytond/tests/test_transaction.py index fc8dbee296..a7ea61cce2 100644 --- a/trytond/tests/test_transaction.py +++ b/trytond/tests/test_transaction.py @@ -121,7 +121,3 @@ class TransactionTestCase(unittest.TestCase): dm.tpc_vote.assert_not_called() dm.tpc_abort.assert_called_once_with(transaction) dm.tpc_finish.assert_not_called() - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(TransactionTestCase) diff --git a/trytond/tests/test_tree.py b/trytond/tests/test_tree.py index 0c8cb86036..6ae6060cca 100644 --- a/trytond/tests/test_tree.py +++ b/trytond/tests/test_tree.py @@ -429,7 +429,3 @@ class TreeMixinTestCase(unittest.TestCase): with self.assertRaises(RecursionError): parent1.parents = [child] parent1.save() - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(TreeMixinTestCase) diff --git a/trytond/tests/test_trigger.py b/trytond/tests/test_trigger.py index 43f88d554c..04b555b1e4 100644 --- a/trytond/tests/test_trigger.py +++ b/trytond/tests/test_trigger.py @@ -479,7 +479,3 @@ class TriggerTestCase(unittest.TestCase): # Restart the cache on the get_triggers method of ir.trigger Trigger._get_triggers_cache.clear() - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(TriggerTestCase) diff --git a/trytond/tests/test_tryton.py b/trytond/tests/test_tryton.py index fe3a0a7678..188d64209c 100644 --- a/trytond/tests/test_tryton.py +++ b/trytond/tests/test_tryton.py @@ -37,13 +37,18 @@ from trytond.wizard import StateAction, StateView __all__ = ['DB_NAME', 'USER', 'CONTEXT', 'activate_module', 'ModuleTestCase', 'with_transaction', - 'doctest_setup', 'doctest_teardown', 'doctest_checker', - 'suite', 'all_suite', 'modules_suite'] + 'doctest_setup', 'doctest_teardown', 'doctest_checker'] Pool.start() USER = 1 CONTEXT = {} -DB_NAME = os.environ['DB_NAME'] +if 'DB_NAME' in os.environ: + DB_NAME = os.environ['DB_NAME'] +elif backend.name == 'sqlite': + DB_NAME = ':memory:' +else: + DB_NAME = 'test_' + str(int(time.time())) +os.environ['DB_NAME'] = DB_NAME DB_CACHE = os.environ.get('DB_CACHE') Pool.test = True @@ -1005,64 +1010,8 @@ class TestSuite(unittest.TestSuite): return result -def suite(): +def load_tests(loader, tests, pattern): ''' Return test suite for other modules ''' return TestSuite() - - -def all_suite(modules=None): - ''' - Return all tests suite of current module - ''' - suite_ = suite() - - def add_tests(filename, module_prefix): - if not (filename.startswith('test_') and filename.endswith('.py')): - return - if modules and fn[:-3] not in modules: - return - modname = module_prefix + '.' + filename[:-3] - __import__(modname) - module = sys.modules[modname] - suite_.addTest(module.suite()) - - for fn in os.listdir(os.path.dirname(__file__)): - add_tests(fn, 'trytond.tests') - if pkg_resources is not None: - entry_points = pkg_resources.iter_entry_points('trytond.tests') - for test_entry_point in entry_points: - base_location = os.path.join( - test_entry_point.dist.location, - *test_entry_point.module_name.split('.')) - for fn in os.listdir(base_location): - add_tests(fn, test_entry_point.module_name) - - return suite_ - - -def modules_suite(modules=None, doc=True): - ''' - Return all tests suite of all modules - ''' - if modules: - suite_ = suite() - else: - suite_ = all_suite() - from trytond.modules import create_graph, get_module_list, import_module - graph = create_graph(get_module_list()) - for node in graph: - module = node.name - if modules and module not in modules: - continue - test_module = 'trytond.modules.%s.tests' % module - try: - test_mod = import_module(module, test_module) - except ImportError: - continue - for test in test_mod.suite(): - if isinstance(test, doctest.DocTestCase) and not doc: - continue - suite_.addTest(test) - return suite_ diff --git a/trytond/tests/test_union.py b/trytond/tests/test_union.py index 7d753bd5b6..76eb965387 100644 --- a/trytond/tests/test_union.py +++ b/trytond/tests/test_union.py @@ -101,7 +101,3 @@ class UnionMixinTestCase(unittest.TestCase): child_names = sorted((r.name for r in uroots[2].childs)) self.assertEqual(child_names, ['Child1', 'Child2']) self.assertEqual(uroots[3].childs[0].name, 'Child3') - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(UnionMixinTestCase) diff --git a/trytond/tests/test_user.py b/trytond/tests/test_user.py index e90b4e9539..2b237bacc3 100644 --- a/trytond/tests/test_user.py +++ b/trytond/tests/test_user.py @@ -339,7 +339,3 @@ class UserTestCase(unittest.TestCase): self.assertEqual( User.get_login('user', {'device_cookie': value}), result) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(UserTestCase) diff --git a/trytond/tests/test_wizard.py b/trytond/tests/test_wizard.py index ebb047a8cd..ad20612386 100644 --- a/trytond/tests/test_wizard.py +++ b/trytond/tests/test_wizard.py @@ -152,7 +152,3 @@ class WizardTestCase(unittest.TestCase): with Transaction().set_context( active_model='test.test_wizard.start'): Wizard.execute(session_id, {}, start_state) - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(WizardTestCase) diff --git a/trytond/tests/test_workflow.py b/trytond/tests/test_workflow.py index def71ca640..1254a5e9a7 100644 --- a/trytond/tests/test_workflow.py +++ b/trytond/tests/test_workflow.py @@ -29,7 +29,3 @@ class WorkflowTestCase(unittest.TestCase): wkf.save() Workflowed.run([wkf]) self.assertEqual(wkf.state, 'end') - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(WorkflowTestCase) diff --git a/trytond/tests/test_wsgi.py b/trytond/tests/test_wsgi.py index 4d4d14af94..0217279882 100644 --- a/trytond/tests/test_wsgi.py +++ b/trytond/tests/test_wsgi.py @@ -110,10 +110,3 @@ class WSGIAppTestCase(unittest.TestCase): self.assertEqual(next(response.response), b'baz') self.assertEqual(response.status, "418 I'M A TEAPOT") - - -def suite(): - suite_ = unittest.TestSuite() - suite_.addTests( - unittest.TestLoader().loadTestsFromTestCase(WSGIAppTestCase)) - return suite_