It contains common elements for testing purposes...
Project description
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.
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 and data coverage reports to disk. Default: True
Examples:
python manager.py run-coverage
python manager.py run-coverage --save-report false
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file core_tests-2.1.0.tar.gz.
File metadata
- Download URL: core_tests-2.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7216c566b6115e45c3968ab000c33c14555c7144da2fad827d9f2ac8c04a5ccd
|
|
| MD5 |
00cfe2121874c551c68c8af6bb71d0f7
|
|
| BLAKE2b-256 |
fd9aafb7d0cb371ce7175a35972794323b1d6b672054dd1be7e49833538bb632
|
File details
Details for the file core_tests-2.1.0-py3-none-any.whl.
File metadata
- Download URL: core_tests-2.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3ab680f283015111638ff05907b185a159cd5d66670e780f1a97f8b2faa92b7
|
|
| MD5 |
6fca2b32bbc3edb4c26dd7fcb48e4ba3
|
|
| BLAKE2b-256 |
d2b290567cc6482b0a3f45bb2bab6844c1a24e3ee296cc85ab3a98a74ba93629
|