The name of the database to use for testing. Its value is taken from the environment variable of the same name.


The user id used to test the transactions


The context used to test the transactions


Activate the named module for the tested database.

In case database does not exist and the DB_CACHE environment variable is set then Tryton restores a backup found in the directory pointed by DB_CACHE. DB_CACHE can also be set to the value postgresql://, in that case Tryton create the database using the template found on the server. Otherwise it procees to the creation of the database and the activation of the module.

DB_CACHE_JOBS environment variable defines the number of jobs used for dump and restore operations. The default value is the number of CPU.


class trytond.tests.test_tryton.ModuleTestCase#

A subclass of unittest.TestCase that tests a Tryton module. Some tests are included to ensure that the module works properly.

It creates a temporary database with the module activated in setUpClass and drops it in the tearDownClass method.


Name of the tested module.


A list of extra modules to activate


The language to activate. Default value is en.


class trytond.tests.test_tryton.RouteTestCase#

A subclass of unittest.TestCase to test Tryton routes.

It creates a temporary database with the module activated in setUpClass and drops it in the tearDownClass method.


Name of the tested module.


A list of extra modules to activate


The language to activate. Default value is en.


Returns the name of the database

classmethod RouteTestCase.setUpDatabase()#

A method called by setUpClass after activating the modules in a Transaction. It is used to setup data in the database.


Return a client to simulate requests to the WSGI application.


trytond.tests.test_tryton.with_transaction(user=1, context=None)#

Return a decorator to run a test case inside a Transaction. It is rolled back and the cache cleared at the end of the test.

doctest helpers#


Prepare the run of the doctest by creating a database and dropping it beforehand if necessary. This function should be used as the setUp parameter.

Deprecated since version 4.2: The doctest_setup function should not be used anymore to set up DocFileSuite(). New modules should use activate_modules() instead.


Clean up after the run of the doctest by dropping the database. It should be used as tearDown parameter when creating a DocFileSuite.


A specialized doctest checker to ensure the Python compatibility.

trytond.tests.test_tryton.load_doc_tests(name, path, loader, tests, pattern)#

An helper that follows the load_tests protocol to load as DocTest all *.rst files in directory, with the module name and the path to the module file from which the doc tests are registered. If a file with the same name but the extension .json exists, the test is registered for each globals defined in the JSON list.


A function returning a subclass of unittest.TestSuite that drops the database if it does not exist prior to the run of the tests.



Activate a list of modules for scenario based on proteus doctests.

trytond.tests.tools.set_user(user, config)#

Set the user of the config proteus connection to user.

The module exposes also all the assert methods of unittest.TestCase that can be run doctest scenario.