Skip to main content

core-tests

A reusable library that provides CLI commands for running unittest-based tests and generating code coverage reports. It wraps Python’s built-in unittest framework and coverage into a Click command group so consuming projects can use python manager.py run-tests and python manager.py run-coverage without duplicating that logic across every project in the ecosystem.

This library is intentionally scoped to unittest and coverage. If your project requires pytest-specific features (fixtures, parametrize, plugins, parallel execution), install pytest directly or via core-dev-tools and invoke it standalone — it is a better fit for that use case than routing it through this abstraction layer.


PyPI Downloads Python Versions License Pipeline Status Docs Status Security

Installation

Install from PyPI using pip:

pip install core-tests
uv pip install core-tests  # Or using UV...

Features

  • Unified CLI abstraction: Expose run-tests and run-coverage in any project without duplicating boilerplate — just wire cli_tests into your CommandCollection.

  • Flexible Test Discovery: Supports multiple file patterns out of the box:

    • test_*.py (standard pattern)

    • *_test.py (alternative pattern)

    • tests_*.py (custom pattern)

  • Custom Pattern Support: Override discovery with --pattern for non-standard file layouts.

  • Enforced Coverage: run-coverage applies the fail_under setting of your coverage configuration, or --fail-under for a single run, and exits non-zero when the total is below it.

  • CI-ready Reports: Writes coverage.xml (Cobertura, relative paths) beside the HTML report, so a CI platform can annotate a merge request diff.

  • Test Organization: Target specific test directories (unit, integration, functional, etc.) via --test-type.

  • Branch Coverage Reports: Generate branch-level coverage reports and optional HTML output.

  • DRY principle: One implementation shared across all projects in the ecosystem.

How to Use

Create a manager.py file in your project root to integrate the test commands:

# manager.py
from click.core import CommandCollection
from core_tests.tests.runner import cli_tests

if __name__ == "__main__":
    cli = CommandCollection(sources=[cli_tests()])
    cli()

This setup provides two commands:

  • run-tests: Execute unittest-based test suites

  • run-coverage: Generate code coverage reports

Example usage:

python manager.py run-tests --test-type unit
python manager.py run-coverage

Available Commands

run-tests

Execute unittest-based test suites with flexible options:

Options:

  • --test-type: Folder name under ./tests directory (e.g., unit, integration, functional). Default: unit

  • --pattern: File pattern to match test files (e.g., *.py, test_*.py). Defaults to multi-pattern discovery.

Examples:

# Run unit tests (default)
python manager.py run-tests --test-type unit

# Run integration tests
python manager.py run-tests --test-type integration

# Run tests with a custom file pattern
python manager.py run-tests --test-type functional --pattern "*.py"

# Run tests in a custom folder
python manager.py run-tests --test-type "custom_folder"

run-coverage

Generate code coverage reports across all test directories:

Options:

  • --save-report: Save HTML, XML and data coverage reports to disk. Default: True

  • --fail-under: Minimum total coverage percentage. Exits non-zero below it, and takes precedence over the fail_under setting of the coverage configuration. Default: unset, so the configured value applies.

Examples:

python manager.py run-coverage
python manager.py run-coverage --save-report false
python manager.py run-coverage --fail-under 90

The HTML report lands in htmlcov/, and a Cobertura coverage.xml beside it, with paths relative to the working directory so a CI platform can map them onto the repository.

Quick Start

Setting Up Environment

  1. Install required libraries:

pip install --upgrade pip
pip install virtualenv
  1. Create Python virtual environment:

virtualenv --python=python3.12 .venv
  1. Activate the virtual environment:

source .venv/bin/activate
  1. Install the package:

pip install -e ".[dev]"

Tests and Coverage

python manager.py run-tests --test-type unit
python manager.py run-tests --test-type integration
python manager.py run-tests --test-type functional --pattern "*.py"
python manager.py run-coverage

Using pytest directly

unittest cannot discover standalone test_* functions or use pytest fixtures. If your project relies on those features, invoke pytest directly:

pytest tests/unit/
pytest -n auto --cov=your_package --cov-report=html

Install pytest via pip or through core-dev-tools:

pip install pytest pytest-xdist pytest-cov
# or
pip install ".[dev]"  # if core-dev-tools includes pytest

Contributing

Contributions are welcome! Please:

  1. Fork the repository

  2. Create a feature branch

  3. Write tests for new functionality

  4. Ensure all tests pass: python manager.py run-tests --test-type unit

  5. Run linting: pylint core_tests

  6. Run security checks: bandit -r core_tests

  7. Submit a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

For questions or support, please open an issue on GitLab or contact the maintainers.

Authors

Metadata

Release files for core-tests 2.2.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 core-tests 2.2.0
File Size Uploaded
core_tests-2.2.0.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for core-tests 2.2.0
File Interpreter ABI Platform
core_tests-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / core_tests-2.2.0.tar.gz

Download URL core_tests-2.2.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
653a0cf57ef906bc27133efc33587b90db52f84f4c5dab419cf2985901ba25ea
BLAKE2b-256 checksum
How to use checksums
0da7df8bb04d192ac2f5d14ec6e0225dd61a32c5d39cabb0a34e02bba502f5c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / core_tests-2.2.0-py3-none-any.whl

Download URL core_tests-2.2.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfdb4e5bd31045f97a89053990422356dd8f42410871f19cedb6c7a6d46b6bac
BLAKE2b-256 checksum
How to use checksums
051b85dbc78fac00f590bf231baa2808fce3c5c68d5e5f0f8e459382db960c3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

2.3.1

2 release files

2.3.0

2 release files

This release

2.2.0 This release

2 release files

2.1.0

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.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