ghtest
Coverage-Guided Test Generator for Python
ghtest is a test generation tool that automatically creates regression tests for your Python code. It combines static analysis with coverage-guided feedback to generate (hopefully) high-quality tests that capture the current behavior of your application.
Key Features
- Coverage-Guided Generation: Iteratively generates tests to target missed branches and edge cases.
- VCR Integration: Automatically records and replays external API interactions (like GitHub API calls) using
vcrpy, making tests deterministic and offline-capable. - Scenario Support: Detects CRUD patterns and generates stateful scenario tests (e.g., create -> read -> delete).
- Smart Parameter Suggestion: Analyzes function signatures and type hints to suggest realistic test inputs.
- Portable Tests: Generates standalone
pytestfiles with relative paths, ready to be committed to your repository. - Safe Execution: Includes an interactive mode to prevent accidental execution of destructive functions (like
delete_repo) during test generation. Nevertheless, it is stringly recommended to runghtestin a safe environment.
Installation
pip install ghtest
Usage
Run ghtest on your source directory:
ghtest src/my_project
This will:
- Scan your code for functions.
- Generate initial tests.
- Run them to capture behavior (recording cassettes).
- Analyze coverage to find missed branches.
- Generate targeted tests to fill coverage gaps.
- Output ready-to-run test files in
tests/.
Options
| Option | Description |
|---|---|
--test-dir DIR |
Directory to output generated tests (default: tests) |
--cassette-dir DIR |
Directory to store VCR cassettes (default: tests/cassettes) |
--unsafe |
Run potentially destructive functions without asking for permission |
--interactive, -i |
Enable interactive mode (ask before running destructive tests) |
--verbose, -v |
Increase verbosity level |
--no-cleanup |
Do not clean up existing tests/cassettes before running |
--history |
Use parameter history for suggestions |
--version |
Show version number |
Example
Generate tests for the current directory, asking for permission before running anything risky:
ghtest . --interactive --verbose
How It Works
- Static Analysis:
ghtestparses your code to understand function signatures, types, and dependencies. - Parameter Suggestion: It suggests input values based on types and common patterns.
- Execution & Capture: It runs the functions with the suggested inputs.
- Return values and exceptions are captured.
- File I/O is tracked.
- Network requests are recorded into VCR cassettes.
- Coverage Feedback: It measures code coverage and identifies unexecuted branches (e.g.,
if x > 5:). It then solves for inputs that would trigger those branches and generates new tests. - Code Generation: Finally, it writes out standard Python test files that assert the captured behavior matches the replay.
License
Metadata
Release files for ghtest 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ghtest-0.1.6.tar.gz | 375.0 kB | Without provenance | Details for ghtest-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ghtest-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for ghtest-0.1.6-py3-none-any.whl |
Total release size: 423.3 kB
Release files / ghtest-0.1.6.tar.gz
| Download URL | ghtest-0.1.6.tar.gz |
|---|---|
| Size | 375.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e92006dd32912e55c0743e03d93056ebbb2057c42321c9a2b7e87f01d3aab418
|
|
BLAKE2b-256 checksum How to use checksums |
763b2f1184fb84f31cd0b09edf9d4a16a87fe1d38cbdb1d5ff42b42566999fef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / ghtest-0.1.6-py3-none-any.whl
| Download URL | ghtest-0.1.6-py3-none-any.whl |
|---|---|
| Size | 48.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60d4512158d9eaba0026ecf9b4eda6a6310121424026a5ebf4ae61a1a5caec34
|
|
BLAKE2b-256 checksum How to use checksums |
883366220681f8f0c31c1f989f1ff8b5b3033fe79135868b285185bacc048001
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for ghtest 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.