This file is indexed.

/usr/share/doc/tryton-server-doc/html/_sources/topics/testing.rst.txt is in tryton-server-doc 4.6.3-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
.. _topics-testing:

=======
Testing
=======

Tryton supports both functional and unit tests.

Testing your module
~~~~~~~~~~~~~~~~~~~

Functional tests
----------------

Functional tests are written as doctests_ using proteus.

Unit tests
----------

Tryton provides the :class:`ModuleTestCase` class that bundles a set of tests
that are useful for every module.

Unit tests in `ModuleTestCase` can be decorated with
:func:`trytond.tests.test_tryton.with_transaction` to run the test in a
transaction.

To use it in your own module you just have to inherit from
:class:`ModuleTestCase` and set the class attribute 
:attr:`module <ModuleTestCase.module>` to the name of your module.

.. highlight:: python

::

    from trytond.tests.test_tryton import ModuleTestCase, with_transaction

    class MyModuleTestCase(ModuleTestCase):
        "My Module Test Case"
        module = 'my_module'

        @with_transaction()
        def test_method(self):
            "Test method"
            self.assert_(True)


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:

.. highlight:: 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

.. _doctests: https://docs.python.org/library/doctest.html
.. _unittest: https://docs.python.org/library/unittest.html

Running your module's tests
---------------------------

Tryton provides the script `trytond/tests/run-tests.py`, just invoke it like
that::

    run-tests.py -m my_module

Testing trytond
~~~~~~~~~~~~~~~

Extending tests
---------------

Python modules extending tryton 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::

    run-tests.py [-c configuration]

You can use a different configuration file to check trytond against different
backend.