Replace test setuptools command by unittest discover
issue9215 review389851002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Use unittest discover
|
||||
* Add module tutorial
|
||||
* Test all XML view and SVG icon files are used
|
||||
* Add notification message
|
||||
|
||||
+46
-51
@@ -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 <config>
|
||||
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.
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
@@ -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()
|
||||
|
||||
@@ -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())
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -404,7 +404,3 @@ class ExportDataTestCase(unittest.TestCase):
|
||||
ExportData.export_data_domain(
|
||||
[('boolean', '=', True)], ['boolean']),
|
||||
[[True]])
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(ExportDataTestCase)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -255,7 +255,3 @@ class FieldBooleanTestCase(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.assertEqual(boolean.boolean, True)
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldBooleanTestCase)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -487,7 +487,3 @@ class FieldDateTimeTestCase(unittest.TestCase):
|
||||
DateTime.write([datetime_], {
|
||||
'datetime': datetime.date(2009, 1, 1),
|
||||
})
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldDateTimeTestCase)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -928,7 +928,3 @@ class FieldDictUnaccentedTestCase(ExtensionTestCase):
|
||||
])
|
||||
|
||||
self.assertListEqual(dicts, [dict_])
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldDictTestCase)
|
||||
|
||||
@@ -455,7 +455,3 @@ class FieldFloatTestCase(unittest.TestCase):
|
||||
Float.write([float_], {
|
||||
'digits': 0,
|
||||
})
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldFloatTestCase)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -344,7 +344,3 @@ class FieldIntegerTestCase(unittest.TestCase):
|
||||
Integer.write([integer], {
|
||||
'integer': 'non integer',
|
||||
})
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldIntegerTestCase)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -526,7 +526,3 @@ class FieldNumericTestCase(unittest.TestCase):
|
||||
Numeric.write([numeric], {
|
||||
'digits': 0,
|
||||
})
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldNumericTestCase)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -317,7 +317,3 @@ class FieldOne2OneTestCase(unittest.TestCase):
|
||||
One2One.write([one2one2], {
|
||||
'one2one': target.id,
|
||||
})
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldOne2OneTestCase)
|
||||
|
||||
@@ -524,7 +524,3 @@ class FieldReferenceTestCase(unittest.TestCase):
|
||||
'reference': str(target),
|
||||
}])
|
||||
self.assertEqual(reference.reference, target)
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldReferenceTestCase)
|
||||
|
||||
@@ -242,7 +242,3 @@ class FieldSelectionTestCase(unittest.TestCase):
|
||||
}])
|
||||
|
||||
self.assertEqual(selection.dyn_select_static_string, '1')
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldSelectionTestCase)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -485,7 +485,3 @@ class FieldTimeTestCase(unittest.TestCase):
|
||||
Time.write([time], {
|
||||
'time': datetime.date(2009, 1, 1),
|
||||
})
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldTimeTestCase)
|
||||
|
||||
@@ -475,7 +475,3 @@ class FieldTimeDeltaTestCase(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
timedelta.timedelta,
|
||||
datetime.timedelta(seconds=42.5))
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(FieldTimeDeltaTestCase)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -147,7 +147,3 @@ class ModelSingletonTestCase(unittest.TestCase):
|
||||
|
||||
Singleton.delete([singleton])
|
||||
self.assertEqual(singleton2.name, 'test')
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(ModelSingletonTestCase)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -95,7 +95,3 @@ class MPTTTestCase(TreeTestCaseMixin, unittest.TestCase):
|
||||
}])],
|
||||
}])
|
||||
self.check_tree()
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(MPTTTestCase)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -32,8 +32,3 @@ class SequenceOrderedMixinTestCase(unittest.TestCase):
|
||||
models.insert(0, model)
|
||||
|
||||
self.assertListEqual(Order.search([]), models)
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(
|
||||
SequenceOrderedMixinTestCase)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -85,5 +85,4 @@ class ResTestCase(ModuleTestCase):
|
||||
self.assertFalse(Warning_.check('test'))
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(ResTestCase)
|
||||
del ModuleTestCase
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -112,7 +112,3 @@ class SendmailTestCase(unittest.TestCase):
|
||||
|
||||
server.sendmail.assert_not_called()
|
||||
self.assertFalse(datamanager.queue)
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(SendmailTestCase)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -429,7 +429,3 @@ class TreeMixinTestCase(unittest.TestCase):
|
||||
with self.assertRaises(RecursionError):
|
||||
parent1.parents = [child]
|
||||
parent1.save()
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(TreeMixinTestCase)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user