Skip to main content

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…


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

  • 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

  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 "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:

  1. Use parallel execution for independent tests:

    pytest -n auto
  2. Run fast unit tests first during development:

    pytest tests/unit/ -n auto
  3. Run functional tests with limited parallelism:

    pytest tests/functional/ -n 2  # Avoid AWS rate limits
  4. Use markers to run specific test subsets:

    pytest -m "unit and not slow" -n auto

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: pytest -n auto

  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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

core_tests-2.0.5.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

core_tests-2.0.5-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file core_tests-2.0.5.tar.gz.

File metadata

  • Download URL: core_tests-2.0.5.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for core_tests-2.0.5.tar.gz
Algorithm Hash digest
SHA256 1920861c3607a1435f9d0ec9143fd682c2263bb0f56d3b99ba1b75396b8721b6
MD5 2743b4690420148fbad1cef97cb6f5ca
BLAKE2b-256 9e7cca65ac405ab9d7ca536b226ea79575ecc50d6669b49896e58c961cfcf728

See more details on using hashes here.

File details

Details for the file core_tests-2.0.5-py3-none-any.whl.

File metadata

  • Download URL: core_tests-2.0.5-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.3

File hashes

Hashes for core_tests-2.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f3854b5e3587235877fa512643e11e383698205305db3e848915bb7c67c0a428
MD5 a17e39fe15b5aa37c77726a1e8758a10
BLAKE2b-256 4298f5a3ce28ac76727d706ca4ad5300dd64d27927ee69ec276242399372b189

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page