Skip to main content

py.test plugin to run Odoo tests

Project description

pytest plugin to run Odoo tests

This lib allows to run the tests built in Odoo addons which are using Python’s unittest, but with the comfort of the pytest CLI. Also allowing to run tests without updating given module.

Odoo’s –test-enable machinery and pytest-odoo do not cover exactly the same scope. The Odoo’s test runner runs the tests during the upgrades of the addons, that’s why they need the “at install” and “post install” markers.

Running tests during upgrades of addons is waaay too slow to work efficiently in a TDD mode, that’s where pytest-odoo shines. Consider that all the tests are running post-install with pytest-odoo, as you must run the upgrade of the addon before (but only when needed vs each run).

At the end of the day, its beneficial to run the Odoo tests with –test-enable because, as in very rare conditions, a test can pass with pytest-odoo but not with the “at install” tests run during the upgrade (or the oposite). Pytest-odoo can be considered a development tool, but not the tool that should replace entirely –test-enable in a CI.

See also the official Odoo documentation on writing tests.

Usage

install via:

pip install pytest-odoo

usage:

pytest -s --odoo-database=test --odoo-log-level=debug_sql [--odoo-http] [--odoo-skip-at-install]

The custom options are:

  • --odoo-database: name of the database to test.

  • --odoo-log-level: log level as expected by odoo. As time of writing: info, debug_rpc, warn, test, critical, debug_sql, error, debug, debug_rpc_answer. The default is critical to have a clean output.

  • --odoo-config: path of the odoo.cfg file to use.

  • --odoo-http: Allow to launch the Odoo http instance

  • --odoo-skip-at-install: use to skip tests that are decorated with @tagged(“at_install”) (Note: this is not the default behavior because Odoo set this tag by default if not defined).

Alternatively, you can use environment variables, like the Odoo Docker image:

  • HOST: hostname of the database server

  • PORT: port of the database server

  • USER: username to access the database

  • PASSWORD: password to access the database

These only work in addition to --odoo-database.

You can use the ODOO_RC environment variable using an odoo configuration file, containing at least the database option with the name of the database to test:

export ODOO_RC=/path/to/odoo/config.cfg
pytest ...

The plugin is also compatible with distributed run provided by the pytest-xdist library. When tests are distributed, a copy of the database is created for each worker at the start of the test session. This is useful to avoid concurrent access to the same database, which can lead to deadlocks. The provided database is therefore used only as template. At the end of the tests, all the created databases are dropped.

The plugin is also compatible with pytest-subtests library. When test use the subTest context manager you’ll get a nice output for each sub-tests failing.

Prerequisites

To run the integration tests (which install Odoo dependencies), you need to have the following system dependencies installed (Debian/Ubuntu):

sudo apt-get install python3-dev libxml2-dev libxslt1-dev libsasl2-dev libldap2-dev libssl-dev libpq-dev postgresql-client

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_odoo-2.2.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_odoo-2.2.0-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_odoo-2.2.0.tar.gz.

File metadata

  • Download URL: pytest_odoo-2.2.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytest_odoo-2.2.0.tar.gz
Algorithm Hash digest
SHA256 d2413a9a825726bc3255c30beeeb715c721284956565ec8045e22b2aa94ea416
MD5 f91c707f686ea088a03903b295ee167a
BLAKE2b-256 068bf683d2358a8e8c6ffe2340ad44133ada36b96952c384770d0a79435666cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_odoo-2.2.0.tar.gz:

Publisher: pypi.yml on camptocamp/pytest-odoo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_odoo-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_odoo-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytest_odoo-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e9ce5b770dca67dcd0af8c7e47b39ec5b14b47c81416c5e6b19cdfa6a21a9ca
MD5 c22de98ebb427d280b28b05c388f90fc
BLAKE2b-256 efa413f4c8a4188a54df8449bc72569e3c0910644849eb3f42c986e28c826fa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_odoo-2.2.0-py3-none-any.whl:

Publisher: pypi.yml on camptocamp/pytest-odoo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page