Chapter 12 - Odoo 15 Development Book

Tagged python test

In Odoo, we can run the test cases using tagged selection. A decorator to tag points BaseCase objects. Tags are put away in a set that can be gotten to from a 'test_tags' trait. While composing tests, the tagged() decorator can be utilized in test classes to add or eliminate tags. What's more, the decorator's contentions are tag names as strings. While utilizing class legacy, the tags are NOT acquired. Of course, tests are pursued once right the comparing module has been introduced. Experiments can likewise be arranged to pursue all modules that have been installed and not pursue right the module installation.

Some special tags are listed bellow:

  • Standard - All Odoo tests that acquire from BaseCase are verifiably tagged standard. --test-tags likewise default to standard. That infers untagged tests will be executed naturally when tests are empowered.
  • At_install - The test will be executed soon after the module establishment and before various modules are introduced. This is a default implicit tag.
  • Post_install - Implies that the test will be executed after every one of the modules are installed. You need this for HttpCase tests more often than not.

Post_install is usually paired with -at_install when tagging a test class

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

Tags can be prefixed with the less (- ) sign, to eliminate them rather than add or select them. For example, in the event that you don't believe your test should be executed as a matter of course you can eliminate the standard tag:

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

In the above example, This test will not be executed by default. To run it, the relevant tag ( external ) will have to be selected explicitly.

Invocation

--test-tags can be utilized to select/filter tests to run on the command line. It suggests -- test-enable,so it's not important to determine -- test-enable while utilizing - - test-tags.

When starting Odoo with --test-enable, the option defaults to +standard meaning tests tagged standard (explicitly or implicitly) will be run by default.

Command to run the test cases using test-tags:

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

  • The - specifies if we want to include or exclude tests matching this spec.
  • The tag will match tags added on a class with a tagged() decorator
  • * will match all tags

Example:

  • If you want to test specific tag:
  • odoo-bin --test-tags standard,external

    The config switch parameter also accepts the + and - prefixes. The - (minus) prefix is made to deselect tests tags with the prefixed tags, regardless of whether they are chosen by other indicated tags. For example, on the off chance that there are standard tests that are likewise tagged as external, you can run all standard tests with the exception of the external ones:

    odoo-bin --test-tags 'standard,-slow'

  • If you want to test the module:
  • odoo-bin --test-tags /sale

  • If you want to test a specific function with a unique name:
  • odoo-bin --test-tags .test_currency_post

  • Run the tests from the sale module but not the ones tagged as standard:
  • odoo-bin --test-tags '/sale,-slow'

  • Run only the tests from sale or tagged as external:
  • odoo-bin --test-tags '-standard, external, /sale’

whatsapp
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