Skip to content

Commit aababc4

Browse files
committed
[IMP] tests: make post_install the default
closes #6670 Signed-off-by: Sébastien Theys (seb) <[email protected]>
1 parent 9ede17c commit aababc4

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
@@ -46,7 +46,7 @@ Before knowing how to write tests, we need to know how to run them.
4646
specifies if we want to include or exclude tests
4747
matching this spec. The tag will match tags added on a
4848
class with a @tagged decorator (all Test classes have
49-
'standard' and 'at_install' tags until explicitly
49+
'standard' and 'post_install' tags until explicitly
5050
removed, see the decorator documentation). '*' will
5151
match all tags. If tag is omitted on include mode, its
5252
value is 'standard'. If tag is omitted on exclude
@@ -173,17 +173,16 @@ coming from modules your module doesn't depend on.
173173

174174
.. code-block:: python
175175
176-
from odoo.tests.common import TransactionCase
177-
from odoo.tests import tagged
176+
from odoo.tests import tagged, TransactionCase
178177
179178
# The CI will run these tests after all the modules are installed,
180179
# not right after installing the one defining it.
181-
@tagged('post_install', '-at_install') # add `post_install` and remove `at_install`
180+
@tagged('post_install') # this is the default
182181
class PostInstallTestCase(TransactionCase):
183182
def test_01(self):
184183
...
185184
186-
@tagged('at_install') # this is the default
185+
@tagged('at_install', '-post_install') # add `at_install` and remove `post_install`
187186
class AtInstallTestCase(TransactionCase):
188187
def test_01(self):
189188
...
@@ -239,13 +238,12 @@ These test classes are built on top of the ``unittest`` python module.
239238

240239
.. code-block:: python
241240
242-
from odoo.tests.common import TransactionCase
241+
from odoo.tests import TransactionCase
243242
from odoo.exceptions import UserError
244-
from odoo.tests import tagged
243+
245244
246245
# The CI will run these tests after all the modules are installed,
247246
# not right after installing the one defining it.
248-
@tagged('post_install', '-at_install')
249247
class EstateTestCase(TransactionCase):
250248
251249
@classmethod

0 commit comments

Comments
 (0)