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.
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
Install required libraries:
pip install --upgrade pip
pip install virtualenv
Create Python virtual environment:
virtualenv --python=python3.12 .venv
Activate the virtual environment:
source .venv/bin/activate
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:
Fork the repository
Create a feature branch
Write tests for new functionality
Ensure all tests pass: python manager.py run-tests --test-type unit
Run linting: pylint core_tests
Run security checks: bandit -r core_tests
Submit a pull request
License
This project is licensed under the MIT License. See the LICENSE file for details.
Links
Support
For questions or support, please open an issue on GitLab or contact the maintainers.
Metadata
Release files for core-tests 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| core_tests-2.3.0.tar.gz | 10.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| core_tests-2.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.2 kB
Release files / core_tests-2.3.0.tar.gz
| Download URL | core_tests-2.3.0.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
994437b93962722b08b7f0358258f88e8b91276372ce09cb20e5bed044eb0951
|
|
BLAKE2b-256 checksum How to use checksums |
83ff40073a2d1eda1e3225f9522f048bff293f2ba9fc5253a856e03d99035e4e
|
| 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.0-py3-none-any.whl
| Download URL | core_tests-2.3.0-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d1af06cdd2002a424d9f2beb305f33a81207427ed42040f76a1b793a859f25e
|
|
BLAKE2b-256 checksum How to use checksums |
9f6a717802d640e047bb940c296ae0e4815aff87576aa4fecc632b040ddb425d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|