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, and the JUnit XML of the results to .reports/, so it can show a test report instead of console output.

  • 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 the reports to disk: the HTML and XML coverage reports, and the JUnit XML of the results in .reports/. 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.3.1

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.3.1
File Size Uploaded
core_tests-2.3.1.tar.gz 10.5 kB Details

Built distribution (wheel)

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

Total release size: 19.2 kB

Release files / core_tests-2.3.1.tar.gz

Download URL core_tests-2.3.1.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b3c8826065fb6c6a1b5bb4cbbab01ca50116430fe7f8b721dd7fe4a8e1772705
BLAKE2b-256 checksum
How to use checksums
d177b79363e94cb2847dd020773f5080d38554c36a8e5acf9e20fd21e5e7d2d6
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.3.1-py3-none-any.whl

Download URL core_tests-2.3.1-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
191e15bff080be8b0d79c97db84b6f5bdb7398fbf5839291a9d6305588f929bc
BLAKE2b-256 checksum
How to use checksums
c59d97bd2425bd064a16a4e4baeedeb1c0797409562e0cce4cbb2b2760b43dd4
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

This release

2.3.1 This release

2 release files

2.3.0

2 release files

2.2.0

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