Skip to Content

ensure_testing_scaffold.sh

PMIverse Test Scaffold Generator for Odoo Addons and Repositories

Overview

ensure_testing_scaffold.sh is an idempotent utility that enforces a PMIverse-compliant pytest testing structure for:

  • a single Odoo addon (--addon), or\
  • an entire Odoo repository containing multiple addons (--repo).

It standardizes test layout, injects PMIverse-managed templates, and ensures that every addon contains a functional and minimal pytest scaffold.

This script is part of the PMISuite tooling suite. Templates referenced herein are sourced from:

/srv/pmiverse/_pmiconfig/testkit/pytest/

Features

Idempotent Scaffold Creation

The script only creates or overwrites files when appropriate:

  • Existing files are preserved unless --force is specified.\
  • Optional smoke test generation can be toggled via --smoke y|n.

Files Created Per Addon


File Description


__init__.py Imports PMIverse pytest markers and initializes the test package.

conftest.py Common test configuration sourced from PMIverse templates.

test_smoke_installation.py Optional smoke test validating addon installation. The script inserts the addon name dynamically.


Repository-Level Files

When invoked with --repo, the script:

  • Scans for all __manifest__.py files and applies scaffolding to each addon.
  • Ensures a root-level pytest.ini exists, copying from:\ /srv/pmiverse/_pmiconfig/testkit/pytest/pytest.base.ini

Logging

All operations are logged to:

/srv/pmiverse/logs/test_scaffold_<timestamp>.log

Requirements and Dependencies

  • Bash 4+\
  • A standard Odoo addon structure with an __manifest__.py\
  • PMISuite configuration directory:
/srv/pmiverse/_pmiconfig/testkit/pytest/
├── templates/tests_init.py
├── conftest.base.py
├── templates/test_smoke_installation.py.tmpl
└── pytest.base.ini

Usage

ensure_testing_scaffold.sh --addon <addon_dir> [--force] [--smoke y|n]
ensure_testing_scaffold.sh --repo <repo_root> [--force] [--smoke y|n]

Arguments

Option Description


--addon <path> Path to a single addon directory. --repo <path> Path to a repository containing multiple addons. --force Overwrite existing scaffold files. --smoke y|n Generate smoke test file (default: yes). --dry-run Perform a dry run without modifications. -h, --help Show inline documentation.


Examples

Scaffold a Single Addon

./ensure_testing_scaffold.sh --addon addons/my_module

Scaffold All Addons in a Repository

./ensure_testing_scaffold.sh --repo /srv/odoo/custom/src

Force Overwrite

./ensure_testing_scaffold.sh --addon my_addon --force

Disable Smoke Tests

./ensure_testing_scaffold.sh --repo my_repo --smoke n

Dry Run

./ensure_testing_scaffold.sh --addon my_addon --dry-run

Behaviour Summary

  • Discovers addons via find <repo> -name "__manifest__.py".
  • Creates <addon>/tests/ when missing.
  • Writes template-backed files unless --force is used.
  • Replaces {{ADDON_NAME}} in smoke test template.
  • Ensures repository-level pytest.ini exists.
  • Logs all steps to a timestamped log file.

Idempotency ensures repeated runs remain safe and deterministic.


Error Handling

Exit codes:

  • 0 --- Success\
  • 1 --- Invalid arguments or missing templates\
  • >1 --- System-level errors (strict bash flags enabled)

CI Integration

This script is suitable for:

  • Pre-commit or pre-pipeline validation\
  • Automated enforcement of PMIverse testing policy\
  • Ensuring minimal test readiness before running pytest

Maintenance Notes

  • Templates should be updated centrally under _pmiconfig/testkit/pytest.
  • The script purposely avoids Odoo-specific logic to remain repository-agnostic.
  • When adding new scaffold elements, maintain idempotency guarantees.

License

Copyright (c) 2025\ LUXIM d.o.o., Slovenia -- Matjaž Mozetič

Part of PMISuite.\ See the repository-level README.md for the repository license statement.