Skip to main content

pytest-testinfra-exporter

Backend-pluggable pytest reporting plugin with preserved pytest-testinfra host parsing behavior.

Installation

From the pytest-testinfra-exporter directory, install the plugin in editable mode:

pip install -e .

If you are standing one level above this directory, use:

pip install -e ./pytest-testinfra-exporter

Pytest will auto-discover the plugin through the package's pytest11 entry point, so no conftest.py changes are required.

Install a database driver if you plan to use a backend:

pip install -e ".[mariadb]"

or:

pip install -e ".[postgres]"

Usage

Once installed, enable reporting directly from the pytest command line:

pytest --storage-report --report-backend=mariadb

The plugin is loaded automatically during pytest startup.

Overview

This project now follows a Strategy + Adapter architecture:

  • Core pytest hooks are implemented in plugin.py.
  • Storage is delegated through AbstractStorageBackend in backend.py.
  • MariaDB support is implemented as MariaDBBackend in backends/mariadb.py.
  • PostgreSQL support is implemented as PostgresBackend in backends/postgres.py.
  • Normalized payloads are represented by dataclasses in models.py.

The testinfra-specific logic is intentionally unchanged (including parsing of salt://, ssh://, fixture host resolution, and nodeid parsing).


Package structure

  • models.py — dataclasses used by the core reporter and backends.
  • backend.py — backend interface contract.
  • backends/mariadb.py — MariaDB adapter implementation.
  • backends/postgres.py — PostgreSQL adapter implementation.
  • plugin.py — pytest hooks, helper utilities, and failure tagging.
  • schema/db.sql — full MariaDB schema reset/apply script.
  • failure_mapper/failure_map.yaml — failure tag mapping rules.
  • docs/index.rst — Sphinx documentation entry point.
  • docs/usage.rst — Sphinx usage guide.
  • docs/api.rst — Sphinx API reference.

Runtime architecture

pytest lifecycle hooks (plugin.py)
  -> build backend strategy (--report-backend)
  -> accumulate TestResultRecord objects in memory
  -> backend.save_results(run_id, results)
  -> backend.session_finish(run_id, counters)

Hook flow

  1. pytest_sessionstart
    • creates run metadata (TestRunSummary)
    • initializes selected backend
    • persists session start
  2. pytest_runtest_makereport
    • captures metadata per nodeid (test name, suite, class, host, markers)
  3. pytest_runtest_logreport
    • merges phase reports (setup/call/teardown)
    • computes final status and captured artifacts
    • appends TestResultRecord
  4. pytest_sessionfinish
    • computes final counters
    • delegates persistence to backend
  5. pytest_terminal_summary
    • prints reporter and tagger status

CLI options

Option Default Description
--storage-report False Enable reporting pipeline.
--report-backend mariadb Storage backend strategy selector (mariadb, postgres).
--datastore-config datastores/default.yaml Path to a YAML file with datastore connection settings. The datastore.<report-backend> section is used. Explicit CLI options override its values.
--run-name Start datetime Human-readable run name stored with the run. Defaults to YYYY-MM-DD HH:MM:SS.
--mariadb-host localhost MariaDB host.
--mariadb-port 3306 MariaDB port.
--mariadb-user testinfra_user MariaDB username.
--mariadb-password password MariaDB password.
--mariadb-database testinfra_reports MariaDB database name.
--mariadb-suite-version None Suite version string (for example git SHA).
--mariadb-init-schema False Run idempotent schema creation/migrations.
--failure-map failure_mapper/failure_map.yaml Failure tagging rules file.
--postgres-host localhost PostgreSQL host.
--postgres-port 5432 PostgreSQL port.
--postgres-user postgres PostgreSQL username.
--postgres-password password PostgreSQL password.
--postgres-database testinfra_reports PostgreSQL database name.
--postgres-init-schema False Run idempotent PostgreSQL schema creation.

Example usage

MariaDB

pytest tests/ \
  --storage-report \
  --report-backend mariadb \
   --run-name "manual-run" \
  --mariadb-host 127.0.0.1 \
  --mariadb-port 3306 \
  --mariadb-user testinfra_user \
  --mariadb-password password \
  --mariadb-database testinfra_reports \
  --mariadb-suite-version "$(git rev-parse --short HEAD)" \
  --mariadb-init-schema

PostgreSQL

pytest tests/ \
  --storage-report \
  --report-backend postgres \
  --postgres-host 127.0.0.1 \
  --postgres-port 5432 \
  --postgres-user postgres \
  --postgres-password password \
  --postgres-database testinfra_reports \
  --postgres-init-schema

Datastore config file

Instead of passing connection flags on every invocation, define them once in a YAML file and select the backend with --report-backend. When --datastore-config is not supplied, the bundled datastores/default.yaml is used:

datastore:
  mariadb:
    host: 'localhost'
    port: 3306
    user: 'testinfra_user'
    password: 'password'
    database: 'testinfra_reports'
  postgres:
    host: 'localhost'
    port: 5432
    user: 'postgres'
    password: 'password'
    database: 'testinfra_reports'
pytest tests/ \
  --storage-report \
  --report-backend mariadb \
  --datastore-config datastore.yaml

Any explicit CLI option (for example --mariadb-user, --mariadb-port) overrides the corresponding value from the YAML file.


Dependencies

  • MariaDB backend: PyMySQL
  • PostgreSQL backend: psycopg2-binary
  • Failure tagging: PyYAML
pip install PyMySQL psycopg2-binary pyyaml

Failure tagging

FailureTagger loads YAML rules from failure_mapper/failure_map.yaml and applies first-match classification for fail/error results.

Supported matching:

  • match_type: exact (substring)
  • match_type: regex (re.search)

Sphinx documentation

A Sphinx-ready docs tree is now included:

  • docs/index.rst
  • docs/usage.rst
  • docs/api.rst

These files use autodoc directives for:

  • models
  • backend
  • plugin
  • backends.mariadb
  • backends.postgres

Example minimal docs/conf.py:

extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.napoleon",
    "sphinx.ext.viewcode",
]

Build docs from project root:

sphinx-build -b html docs docs/_build/html

Notes

  • Timestamp persistence remains naive IST for compatibility with existing dashboards.
  • Existing testinfra host extraction behavior is preserved.
  • Current backend implementations: mariadb, postgres.

Release files for pytest-testinfra-exporter 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-testinfra-exporter 0.4.0
File Size Uploaded
pytest_testinfra_exporter-0.4.0.tar.gz 25.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-testinfra-exporter 0.4.0
File Interpreter ABI Platform
pytest_testinfra_exporter-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 56.4 kB

Release files / pytest_testinfra_exporter-0.4.0.tar.gz

Download URL pytest_testinfra_exporter-0.4.0.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c0a2ad3293507de49a379fd9821b84ca3949bb8557e2961f0bce925b0d250daa
BLAKE2b-256 checksum
How to use checksums
5ed05bfe61a0b39255174c9fbafd3b181ecca5562f176b218be825cec365c2c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21

Release files / pytest_testinfra_exporter-0.4.0-py3-none-any.whl

Download URL pytest_testinfra_exporter-0.4.0-py3-none-any.whl
Size 31.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30ae10587ee9d8a320da0ff6c93720e74e0b70067f3044d50cba376c47811c56
BLAKE2b-256 checksum
How to use checksums
94927303b25a9ff01cdfc5dd68fae191830ba887ea05fb337338dddb7a89b690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page