Skip to main content

A pluggy-based pytest plugin and CLI tool for ensuring your test suite mirrors your source code structure

Project description

pytest-mirror

A pluggy-based pytest plugin and CLI tool for ensuring your test suite mirrors your source code structure.

Overview

pytest-mirror helps you:

  • Ensure every Python module in your package has a corresponding test file.
  • Quickly generate missing test stubs for new or existing code.
  • Validate that your test suite structure matches your package structure.
  • Integrate with pytest as a plugin or use as a standalone CLI.

Built with pluggy for extensible plugin architecture.

Features

  • Test Structure Validation: Checks for missing test files that should correspond to your package modules.
  • Test Stub Generation: Automatically creates test files and __init__.py as needed, with a failing test stub.
  • CLI and Plugin: Use as a command-line tool or as a pytest plugin.
  • Customizable: Specify package and test directories.

Installation

pip install pytest-mirror

For local development:

# Clone the repository and install in development mode
git clone https://github.com/dvonpasecky/pytest-mirror.git
cd pytest-mirror
pip install -e .

Or with uv:

uv sync

Usage

CLI

# With explicit directories:
pytest-mirror generate --package-dir src/your_package --tests-dir tests
pytest-mirror validate --package-dir src/your_package --tests-dir tests

# Or let pytest-mirror auto-detect your package and tests directories:
pytest-mirror generate
pytest-mirror validate
  • generate: Creates missing test files for all modules in your package.
  • validate: Checks for missing test files and reports any discrepancies.

As a pytest Plugin

Add pytest-mirror to your test dependencies. The plugin will automatically:

  1. Validate your test structure when running pytest
  2. Auto-generate missing test files (unless disabled)
pytest

Plugin Configuration

You can customize the plugin behavior using:

  • Command-line flags:
    • --mirror-package-dir (path to your package)
    • --mirror-tests-dir (path to your tests)
    • --mirror-no-generate (disable automatic test generation)

If package and tests directories are not specified, the plugin will auto-detect the most likely directories.

Auto-generation behavior: By default, the plugin will automatically create missing test files when pytest runs. Use --mirror-no-generate to disable this and only validate structure.

API

You can also use the core functions in your own scripts:

from pytest_mirror import generate_missing_tests, find_missing_tests

# Generate missing test files
generate_missing_tests('src/your_package', 'tests')

# Find missing test files without creating them
missing = find_missing_tests('src/your_package', 'tests')
print(missing)

Development

  • All code is in src/pytest_mirror/.
  • Tests are in tests/ with 1:1 module mirroring.
  • Run tests with:
pytest
# or with uv:
uv run pytest
  • Lint and check style with:
ruff check src/ tests/
# or with uv:
uv run ruff check src/ tests/

Contributing

Contributions are welcome! Please:

  • Add or update tests for your changes.
  • Ensure all tests and linters pass.
  • Update this README if needed.

License

MIT License. See LICENSE.


This project is not affiliated with pytest or pluggy, but is built to extend and complement them.

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_mirror-0.1.1.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

pytest_mirror-0.1.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_mirror-0.1.1.tar.gz.

File metadata

  • Download URL: pytest_mirror-0.1.1.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.3

File hashes

Hashes for pytest_mirror-0.1.1.tar.gz
Algorithm Hash digest
SHA256 252e39571070fc1ed74457b060c9c98cc301e73c47898a89ae9c7c046922e6fa
MD5 cf9aea76ee13e2de074a96a3aa42da67
BLAKE2b-256 c77c3e45f5ab5ce857b766d8e878e80e1f97cd947b1970f12dc0b4e2a40f1ef4

See more details on using hashes here.

File details

Details for the file pytest_mirror-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_mirror-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d343b2ef316114c8c059c2e77cc7d87e3e5f3ca1e54847acd74c6e00551ebe6
MD5 84964cd5ba6ac57a10b55d9f4318d2b6
BLAKE2b-256 332d17fdbb020a702fc277424a3ed4c4db14f006c188cc8e828107b1cf27784f

See more details on using hashes here.

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