Skip to content

Commit

Permalink
[IMP] tests: make post_install the default
Browse files Browse the repository at this point in the history
  • Loading branch information
seb-odoo committed Jan 30, 2024
1 parent 9e75bca commit 5b44b70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
33 changes: 12 additions & 21 deletions content/developer/reference/backend/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,6 @@ related to testing Odoo content (modules, mainly):

.. autofunction:: odoo.tests.tagged

By default, tests are run once right after the corresponding module has been
installed. Test cases can also be configured to run after all modules have
been installed, and not run right after the module installation::

# coding: utf-8
from odoo.tests import HttpCase, tagged

# This test should only be executed after all modules have been installed.
@tagged('-at_install', 'post_install')
class WebsiteVisitorTests(HttpCase):
def test_create_visitor_on_tracked_page(self):
Page = self.env['website.page']

The most common situation is to use
:class:`~odoo.tests.TransactionCase` and test a property of a model
in each method::
Expand Down Expand Up @@ -190,7 +177,7 @@ they're not going to get run:
import unittest
from odoo.tests import tagged
@tagged('standard', 'at_install')
@tagged('standard', 'post_install')
class SmallTest(unittest.TestCase):
...
Expand Down Expand Up @@ -234,15 +221,19 @@ Special tags
:option:`--test-tags <odoo-bin --test-tags>` also defaults to ``standard``.

That means untagged test will be executed by default when tests are enabled.
- ``at_install``: Means that the test will be executed right after the module
installation and before other modules are installed. This is a default
implicit tag.

- ``post_install``: Means that the test will be executed after all the modules
are installed. This is what you want for HttpCase tests most of the time.
are installed. This is a default implicit tag.

- ``at_install``: Means that the test will be executed right after the module
installation and before other modules are installed.

This should be used seldomly as it prevents test runs from being parallelized
on runbot. A valuable addition is a comment above to test to explain why it
needs to be run before other modules are installed.

Note that this is *not exclusive* with ``at_install``, however since you
will generally not want both ``post_install`` is usually paired with
``-at_install`` when tagging a test class.
Note that this is *exclusive* with ``post_install`` so ``at_install`` is
usually paired with ``-post_install`` when tagging a test class.

Examples
~~~~~~~~
Expand Down
14 changes: 6 additions & 8 deletions content/developer/tutorials/unit_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Before knowing how to write tests, we need to know how to run them.
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 (all Test classes have
'standard' and 'at_install' tags until explicitly
'standard' and 'post_install' tags until explicitly
removed, see the decorator documentation). '*' will
match all tags. If tag is omitted on include mode, its
value is 'standard'. If tag is omitted on exclude
Expand Down Expand Up @@ -175,17 +175,16 @@ coming from modules your module doesn't depend on.

.. code-block:: python
from odoo.tests.common import TransactionCase
from odoo.tests import tagged
from odoo.tests import tagged, TransactionCase
# The CI will run these tests after all the modules are installed,
# not right after installing the one defining it.
@tagged('post_install', '-at_install') # add `post_install` and remove `at_install`
@tagged('post_install') # this is the default
class PostInstallTestCase(TransactionCase):
def test_01(self):
...
@tagged('at_install') # this is the default
@tagged('at_install', '-post_install') # add `at_install` and remove `post_install`
class AtInstallTestCase(TransactionCase):
def test_01(self):
...
Expand Down Expand Up @@ -241,13 +240,12 @@ These test classes are built on top of the ``unittest`` python module.

.. code-block:: python
from odoo.tests.common import TransactionCase
from odoo.tests import TransactionCase
from odoo.exceptions import UserError
from odoo.tests import tagged
# The CI will run these tests after all the modules are installed,
# not right after installing the one defining it.
@tagged('post_install', '-at_install')
class EstateTestCase(TransactionCase):
@classmethod
Expand Down

0 comments on commit 5b44b70

Please sign in to comment.