It contains common elements for testing purposes...
Project description
core-tests
This project contains basic elements for testing purposes and the ability to run (via console commands) tests and code coverage (unittest-based). This way, we can stick to the DRY – Don’t Repeat Yourself principle and avoid code duplication in each python project where tests coverage and tests execution are expected…
Installation
Install from PyPI using pip:
pip install core-tests
Or using uv:
uv pip install core-tests
Features
Dual Test Engine Support: Run tests using either unittest or pytest frameworks
- Flexible Test Discovery: Supports multiple file patterns:
test_*.py (standard pattern)
*_test.py (alternative pattern)
tests_*.py (custom pattern)
Custom Pattern Support: Specify custom file patterns using the –pattern flag
Test Organization: Run tests by type (unit, integration, functional, etc.)
Coverage Reports: Generate coverage reports with both frameworks
CLI Integration: Easy integration via Click command collections
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 test suites with unittest or pytest
run-coverage: Generate code coverage reports
Example usage:
python manager.py run-tests --test-type unit
python manager.py run-coverage --engine pytest
Available Commands
run-tests
Execute test suites with flexible options:
Options:
--engine: Test engine to use (unittest or pytest). Default: unittest
--test-type: Folder name under ./tests directory (e.g., unit, integration, functional)
--pattern: File pattern to match test files (e.g., *.py, test_*.py). Works with both engines.
Examples:
# Run unit tests with unittest (default)
python manager.py run-tests --test-type unit
# Run integration tests with pytest
python manager.py run-tests --engine pytest --test-type integration
# Run tests with custom pattern
python manager.py run-tests --test-type functional --pattern "test_*.py"
# Run all tests in a custom folder
python manager.py run-tests --test-type "custom_folder"
run-coverage
Generate code coverage reports:
Options:
--engine: Test engine to use (unittest or pytest). Default: unittest
Examples:
# Generate coverage with unittest
python manager.py run-coverage
# Generate coverage with pytest
python manager.py run-coverage --engine pytest
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 "another folder that contains test cases under ./tests"
python manager.py run-tests --test-type functional --pattern "*.py"
Using PyTest
The unittest framework cannot discover or run pytest-style tests, it is designed to discover and run tests that are subclasses of unittest.TestCase and follow its conventions. Pytest-style tests (i.e., functions named test_* that are not inside a unittest.TestCase class, or tests using pytest fixtures, parametrize, etc.) are not recognized by unittest’s discovery mechanism, unittest will simply ignore standalone test functions and any pytest-specific features…
That’s why you can use PyTest if required.
python manager.py run-tests --engine pytest
Test coverage
python manager.py run-coverage # For `unittest` framework...
python manager.py run-coverage --engine pytest # For `PyTest`...
pytest -n auto --cov=core_tests --cov-report=html # Direct `pytest` execution...
Best Practices
When working with pytest, consider these optimization strategies:
Use parallel execution for independent tests:
pytest -n autoRun fast unit tests first during development:
pytest tests/unit/ -n autoRun functional tests with limited parallelism:
pytest tests/functional/ -n 2 # Avoid AWS rate limitsUse markers to run specific test subsets:
pytest -m "unit and not slow" -n auto
Contributing
Contributions are welcome! Please:
Fork the repository
Create a feature branch
Write tests for new functionality
Ensure all tests pass: pytest -n auto
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.0.4.tar.gz.
File metadata
- Download URL: core_tests-2.0.4.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
084a2eaf74cd0e1174f681d1b189993319742b10ffc5e782c26ce2515d9dcea9
|
|
| MD5 |
5cf1b8767784241379eeff1af417e512
|
|
| BLAKE2b-256 |
abab7b62953c7fcbd7da826be643c06f3adde8c91ab6756d595d9552511d4917
|
File details
Details for the file core_tests-2.0.4-py3-none-any.whl.
File metadata
- Download URL: core_tests-2.0.4-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40f29c4a454173c2dcde3a746738cfe29600a6f781a484800067dc797611fd08
|
|
| MD5 |
a637c0a4f29a7046f68fdfa760abc891
|
|
| BLAKE2b-256 |
5dca51f75e89841ef09fecb03551daf4ba68c024f9a0a0ccfad20c829162e926
|