How it works...

By default, all of the test cases are tagged with standard, at_install and the current module's technical name (in our case, the technical name is my_library). Consequently, if you are not using a tagged() decorator, your test case will have these three tags.
In our case, we want to run the test case after installing all of the modules. To do so, we have added a tagged() decorator on the TestBookState class. By default, the test case has the at_install tag. Because of this tag, your test case will run immediately after the module is installed; it will not wait for other modules to be installed. We don't want this, so to remove the at_install tag, we have added -at_install in the tagged function. The tags that are prefixed by - will remove that tag.

By adding -at_install in the tagged() function, we stopped the test case execution after the module installation. As we haven't specified any other tag in this, the test case won't run.

So, we have added a post_install tag. This tag specifies that the test case needs to be run after the installation of all modules is completed.

Before Odoo version 12, the common.at_install() and common.post_install() decorators were used for changing the execution sequence of the test case. In version 12, these decorators were deprecated and replaced by the at_install and post_install tags.

As you have seen, all test cases are tagged with the standard tag, by default. Odoo will run all of the test cases tagged with the standard tag, in case you don't want to run the specific test case all of the time and you only want to run the test case when it is requested. To do so, you need to remove the standard tag by adding -standard in the tagged() decorator, and you need to add a custom tag like this:

@tagged('-standard', 'my_custom_tag')
class TestClass(TransactionCase):
...

All of the non-standard test cases will not run with the --test-enable option. To run the preceding test case, you need to use the --test-tags option, as follows. (Note that here, we do not need to pass the --test-enable option explicitly):

./odoo-bin -c server.conf -i my_library --test-tags=my_custom_tag
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset