Skip to content

Commit a017f31

Browse files
committed
[IMP] tests: make post_install the default
1 parent 1defbf7 commit a017f31

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

content/developer/reference/backend/testing.rst

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,6 @@ related to testing Odoo content (modules, mainly):
5858

5959
.. autofunction:: odoo.tests.tagged
6060

61-
By default, tests are run once right after the corresponding module has been
62-
installed. Test cases can also be configured to run after all modules have
63-
been installed, and not run right after the module installation::
64-
65-
# coding: utf-8
66-
from odoo.tests import HttpCase, tagged
67-
68-
# This test should only be executed after all modules have been installed.
69-
@tagged('-at_install', 'post_install')
70-
class WebsiteVisitorTests(HttpCase):
71-
def test_create_visitor_on_tracked_page(self):
72-
Page = self.env['website.page']
73-
7461
The most common situation is to use
7562
:class:`~odoo.tests.TransactionCase` and test a property of a model
7663
in each method::
@@ -190,7 +177,7 @@ they're not going to get run:
190177
import unittest
191178
from odoo.tests import tagged
192179
193-
@tagged('standard', 'at_install')
180+
@tagged('standard', 'post_install')
194181
class SmallTest(unittest.TestCase):
195182
...
196183
@@ -234,15 +221,19 @@ Special tags
234221
:option:`--test-tags <odoo-bin --test-tags>` also defaults to ``standard``.
235222

236223
That means untagged test will be executed by default when tests are enabled.
237-
- ``at_install``: Means that the test will be executed right after the module
238-
installation and before other modules are installed. This is a default
239-
implicit tag.
224+
240225
- ``post_install``: Means that the test will be executed after all the modules
241-
are installed. This is what you want for HttpCase tests most of the time.
226+
are installed. This is a default implicit tag.
227+
228+
- ``at_install``: Means that the test will be executed right after the module
229+
installation and before other modules are installed.
230+
231+
This should be used seldomly as it prevents test runs from being parallelized
232+
on runbot. A valuable addition is a comment above to test to explain why it
233+
needs to be run before other modules are installed.
242234

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

247238
Examples
248239
~~~~~~~~

content/developer/tutorials/unit_tests.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Before knowing how to write tests, we need to know how to run them.
4848
specifies if we want to include or exclude tests
4949
matching this spec. The tag will match tags added on a
5050
class with a @tagged decorator (all Test classes have
51-
'standard' and 'at_install' tags until explicitly
51+
'standard' and 'post_install' tags until explicitly
5252
removed, see the decorator documentation). '*' will
5353
match all tags. If tag is omitted on include mode, its
5454
value is 'standard'. If tag is omitted on exclude
@@ -175,17 +175,16 @@ coming from modules your module doesn't depend on.
175175

176176
.. code-block:: python
177177
178-
from odoo.tests.common import TransactionCase
179-
from odoo.tests import tagged
178+
from odoo.tests import tagged, TransactionCase
180179
181180
# The CI will run these tests after all the modules are installed,
182181
# not right after installing the one defining it.
183-
@tagged('post_install', '-at_install') # add `post_install` and remove `at_install`
182+
@tagged('post_install') # this is the default
184183
class PostInstallTestCase(TransactionCase):
185184
def test_01(self):
186185
...
187186
188-
@tagged('at_install') # this is the default
187+
@tagged('at_install', '-post_install') # add `at_install` and remove `post_install`
189188
class AtInstallTestCase(TransactionCase):
190189
def test_01(self):
191190
...
@@ -241,13 +240,12 @@ These test classes are built on top of the ``unittest`` python module.
241240

242241
.. code-block:: python
243242
244-
from odoo.tests.common import TransactionCase
243+
from odoo.tests import TransactionCase
245244
from odoo.exceptions import UserError
246-
from odoo.tests import tagged
245+
247246
248247
# The CI will run these tests after all the modules are installed,
249248
# not right after installing the one defining it.
250-
@tagged('post_install', '-at_install')
251249
class EstateTestCase(TransactionCase):
252250
253251
@classmethod

0 commit comments

Comments
 (0)