[FIX] testing: Explain "new" tagging syntax

Syntax was added to explicitly specify a module, class or function with
`--test-tags`: b729a11a12

The documentation was not updated to reflect this, leading to confusion
as people tried to reconcile the documentation with the actual behavior,
without necessarily having seen `odoo-bin --help` which is explicit
about it.

closes odoo/documentation#1279

X-original-commit: 23d0a7a062
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Raf Geens 2021-10-29 15:38:36 +00:00
parent f4f962c0a4
commit 77dd769b08

View File

@ -120,13 +120,15 @@ Subclasses of :class:`odoo.tests.common.BaseCase` (usually through
:class:`~odoo.tests.common.TransactionCase`, :class:`~odoo.tests.common.TransactionCase`,
:class:`~odoo.tests.common.SavepointCase` or :class:`~odoo.tests.common.SavepointCase` or
:class:`~odoo.tests.common.HttpCase`) are automatically tagged with :class:`~odoo.tests.common.HttpCase`) are automatically tagged with
``standard``, ``at_install`` and their source module's name by default. ``standard`` and ``at_install`` by default.
Invocation Invocation
^^^^^^^^^^ ^^^^^^^^^^
:option:`--test-tags <odoo-bin --test-tags>` can be used to select/filter tests :option:`--test-tags <odoo-bin --test-tags>` can be used to select/filter tests
to run on the command-line. to run on the command-line. It implies :option:`--test-enable <odoo-bin --test-enable>`,
so it's not necessary to specify :option:`--test-enable <odoo-bin --test-enable>`
when using :option:`--test-tags <odoo-bin --test-tags>`.
This option defaults to ``+standard`` meaning tests tagged ``standard`` This option defaults to ``+standard`` meaning tests tagged ``standard``
(explicitly or implicitly) will be run by default when starting Odoo (explicitly or implicitly) will be run by default when starting Odoo
@ -157,7 +159,7 @@ have to be selected explicitly:
.. code-block:: console .. code-block:: console
$ odoo-bin --test-enable --test-tags nice $ odoo-bin --test-tags nice
Note that only the tests tagged ``nice`` are going to be executed. To run Note that only the tests tagged ``nice`` are going to be executed. To run
*both* ``nice`` and ``standard`` tests, provide multiple values to *both* ``nice`` and ``standard`` tests, provide multiple values to
@ -166,10 +168,10 @@ are *additive* (you're selecting all tests with *any* of the specified tags)
.. code-block:: console .. code-block:: console
$ odoo-bin --test-enable --test-tags nice,standard $ odoo-bin --test-tags nice,standard
The config switch parameter also accepts the ``+`` and ``-`` prefixes. The The config switch parameter also accepts the ``+`` and ``-`` prefixes. The
``+`` prefix is implied and therefore, totaly optional. The ``-`` (minus) ``+`` prefix is implied and therefore, totally optional. The ``-`` (minus)
prefix is made to deselect tests tagged with the prefixed tags, even if they prefix is made to deselect tests tagged with the prefixed tags, even if they
are selected by other specified tags e.g. if there are ``standard`` tests which are selected by other specified tags e.g. if there are ``standard`` tests which
are also tagged as ``slow`` you can run all standard tests *except* the slow are also tagged as ``slow`` you can run all standard tests *except* the slow
@ -177,7 +179,7 @@ ones:
.. code-block:: console .. code-block:: console
$ odoo-bin --test-enable --test-tags 'standard,-slow' $ odoo-bin --test-tags 'standard,-slow'
When you write a test that does not inherit from the When you write a test that does not inherit from the
:class:`~odoo.tests.common.BaseCase`, this test will not have the default tags, :class:`~odoo.tests.common.BaseCase`, this test will not have the default tags,
@ -194,6 +196,36 @@ they're not going to get run:
class SmallTest(unittest.TestCase): class SmallTest(unittest.TestCase):
... ...
Besides tags you can also specify specific modules, classes or functions to
test. The full syntax of the format accepted by :option:`--test-tags <odoo-bin --test-tags>`
is:
.. code-block::
[-][tag][/module][:class][.method]
So if you want to test the `stock_account` module, you can use:
.. code-block:: console
$ odoo-bin --test-tags /stock_account
If you want to test a specific function with a unique name, it can be specified
directly:
.. code-block:: console
$ odoo-bin --test-tags .test_supplier_invoice_forwarded_by_internal_user_without_supplier
This is equivalent to
.. code-block:: console
$ odoo-bin --test-tags /account:TestAccountIncomingSupplierInvoice.test_supplier_invoice_forwarded_by_internal_user_without_supplier
if the name of the test is unambiguous. Multiple modules, classes and functions
can be specified at once separated by a `,` like with regular tags.
.. _reference/testing/tags: .. _reference/testing/tags:
Special tags Special tags
@ -213,43 +245,36 @@ Special tags
Note that this is *not exclusive* with ``at_install``, however since you Note that this is *not exclusive* with ``at_install``, however since you
will generally not want both ``post_install`` is usually paired with will generally not want both ``post_install`` is usually paired with
``-at_install`` when tagging a test class. ``-at_install`` when tagging a test class.
- *module_name*: Odoo tests classes extending
:class:`~odoo.tests.common.BaseCase` are implicitly tagged with the
technical name of their module. This allows easily selecting or excluding
specific modules when testing e.g. if you want to only run tests from
``stock_account``:
.. code-block:: console
$ odoo-bin --test-enable --test-tags stock_account
Examples Examples
^^^^^^^^ ^^^^^^^^
.. important:: .. important::
Tests will be executed only in the installed or updated modules. So Tests will be executed only in installed modules. If you're starting from
modules have to be selected with the :option:`-u <odoo-bin -u>` or a clean database, you'll need to install the modules with the
:option:`-i <odoo-bin -i>` switches. For simplicity, those switches are :option:`-i <odoo-bin -i>` switch at least once. After that it's no longer
needed, unless you need to upgrade the module, in which case
:option:`-u <odoo-bin -u>` can be used. For simplicity, those switches are
not specified in the examples below. not specified in the examples below.
Run only the tests from the sale module: Run only the tests from the sale module:
.. code-block:: console .. code-block:: console
$ odoo-bin --test-enable --test-tags sale $ odoo-bin --test-tags /sale
Run the tests from the sale module but not the ones tagged as slow: Run the tests from the sale module but not the ones tagged as slow:
.. code-block:: console .. code-block:: console
$ odoo-bin --test-enable --test-tags 'sale,-slow' $ odoo-bin --test-tags '/sale,-slow'
Run only the tests from stock or tagged as slow: Run only the tests from stock or tagged as slow:
.. code-block:: console .. code-block:: console
$ odoo-bin --test-enable --test-tags '-standard, slow, stock' $ odoo-bin --test-tags '-standard, slow, /stock'
.. note:: ``-standard`` is implicit (not required), and present for clarity .. note:: ``-standard`` is implicit (not required), and present for clarity