.

Odoo 16 Development Book

Tagged python test

Odoo allows you to highlight selections and run test cases. Decorator for tagging Points BaseCase objects. The tags are placed in a set accessible through the "test_tags" property. The tagged() decorator can be used on the test class to add or remove tags when assembling the test. Additionally, the decorator's assertion is that the tag name is a string. Tags are not picked up when using class inheritance. Of course, the tests will run once the comparison module is introduced. Instead of tracking module installations directly, you can also adjust your experiment to track all installed modules.

Some special tags are listed below:

At_install - Testing is done immediately after module setup and before various module rollouts. This is a standard implicit tag.

Post_install - It means that tests will be run after all modules are installed. This is mainly needed for HttpCase tests.

Standard - All Odoo tests that acquire from BaseCase are explicitly flagged by default. --test-tags also defaults to standard. So untagged tests naturally run.

Post_install is usually paired with -at_install when tagging test classes.

Subclasses of odoo.tests.common.BaseCase (usually by TransactionCase, SavepointCase, or HttpCase) are automatically marked standard and at_install by default.

Instead of adding or selecting tags, you can prefix them with a minus sign (-) to remove them. If you don't want your tests to run by default, you can remove the default tag.

# -*- coding: utf-8 -*-
from odoo.tests import TransactionCase, tagged
@tagged('-standard', 'mytest')
class MyTest(TransactionCase):

This test is not selected by default. To run, you have to explicitly select the corresponding tag (mytest).

Invocation

You can use --test-tags to select/filter which tests to run on the command line. It means --test-enable, so you don't need to specify --test-enable when using --test-tags.

This option is set to +standard by default. This means that tests tagged as standard (explicit or implicit) are run by default when Odoo is started with --test-enable.

Command to run test cases with test tags:

odoo-bin --test-tags [-][tag][/module][:class][.method]

The ‘-’ indicates to include or exclude tests conforming to this specification. This tag matches tags added to the class using the tagged() decorator.

Example:

    ● odoo-bin --test-tags /purchase

    For testing the module.

    ● odoo-bin --test-tags mytest,standard

    For testing specific tag.Configuration switch parameters also accept + and - prefixes. The - (minus) prefix is used to deselect test tags that have a previous tag, regardless of whether they are selected by other specified tags. For example, if you have a standard test that is also marked as mytest, you can run all standard tests except mytest.

    ● odoo-bin --test-tags .test_date_planned

    For testing specific function with a unique name. This is equivalent to:

    odoo-bin --test-tags /purchase:TestPurchase.test_date_planned

    ● odoo-bin --test-tags '/purchase,-slow'

    Run the tests from the purchase module but not the ones tagged as slow:

    ● odoo-bin --test-tags '-standard, mytest, /student

    Run only the tests from student or tagged as mytest

location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message