A pytest plugin for running Odoo tests with enhanced functionality and integration with oduit-core.
- Automatic Odoo configuration: Integrates with
.oduit.tomlconfiguration files using oduit-core - Automatic module installation: Automatically detects and installs addon modules based on test paths
- Module path resolution: Automatically resolves Odoo addon module paths for proper test discovery
- Test retry management: Disables Odoo's built-in test retry mechanism to work seamlessly with pytest
- Distributed testing support: Works with pytest-xdist for parallel test execution
- HTTP server support: Optional Odoo HTTP server launch for integration tests
pip install pytest-oduitNote: pytest-odoo must not be installed. Never run pytest for testing odoo modules inside the source dir of pytest-oduit (as then the odoo mock is loaded).
- Python >= 3.9
- pytest >= 8
- oduit
- Odoo >= 15.0
Simply run pytest in your Odoo addon directory:
pytestThe plugin will automatically detect which addon modules contain your tests and initialize them in Odoo. For example:
pytest addons/sale # Automatically adds --init=sale
pytest addons/sale addons/purchase # Automatically adds --init=purchase,sale
pytest addons/sale/tests/test_sale.py # Automatically adds --init=saleThis eliminates the need to manually specify --odoo-install for each test run.
This plugin works also together pytest-subtests and pytest-xdist.
--odoo-log-level: Set the log level for Odoo processes during tests (default: 'critical')--odoo-install: Control module installation behavior:- Not specified (default): Automatically detect and install modules based on test paths
--odoo-install=module1,module2: Manually specify modules to install (disables auto-detection)--odoo-install="": Disable all module installation
--oduit-env: Set the oduit config file path (when not specified, uses local.oduit.toml)--odoo-http: Enables http server for testing tours (only needed for Odoo < 18)
By default, the plugin automatically detects which addon modules are being tested and initializes them in Odoo. This eliminates the need to manually specify modules for each test run.
How it works:
- Analyzes the test paths provided to pytest
- Extracts addon names by locating
__manifest__.pyfiles - Automatically appends
--init=<detected_modules>to the Odoo configuration
Examples:
# Auto-detect and install modules
pytest addons/sale # Installs: sale
pytest addons/sale addons/purchase # Installs: purchase, sale
pytest addons/sale/tests/test_sale.py # Installs: sale
# Manually specify modules (overrides auto-detection)
pytest --odoo-install=sale,purchase addons/crm # Installs: sale, purchase (NOT crm)
# Disable all module installation
pytest --odoo-install="" addons/sale # Installs: nothingWhen automatic detection activates:
- A
.oduit.tomlconfiguration file is present or--oduit-envis specified --odoo-installis not provided (no manual override)
Supported path types:
- Addon directories:
addons/my_module - Test files:
addons/my_module/tests/test_something.py - Subdirectories:
addons/my_module/tests/ - Multiple addons:
addons/module_a addons/module_b
The plugin automatically detects and uses .oduit.toml configuration files when available. This provides seamless integration with oduit for database configuration, addon paths, and other Odoo settings.
Example .oduit.toml:
[odoo]
db_name = "test_db"
addons_path = ["./addons", "./custom_addons"]The plugin automatically resolves Odoo addon module paths, ensuring that:
- Test modules in
addon_name/tests/are properly recognized asodoo.addons.addon_name.tests.test_module - Only installable addons (with
installable: Truein__manifest__.py) are collected for testing - Namespace packages are handled correctly
Works seamlessly with pytest-xdist for parallel test execution:
pytest -n auto # Run tests in parallel using all available CPUsThe plugin automatically creates isolated database copies for each worker to prevent conflicts.
cd pytest-oduit
pytestThe plugin includes comprehensive tests that use mock Odoo modules to verify functionality without requiring a full Odoo installation.
AGPLv3 - see LICENSE file for details.
- Holger Nahrstaedt
- Based on original work by Pierre Verkest and Camptocamp SA
Contributions are welcome! Please feel free to submit issues and pull requests.