CLI to generate and update Python unit tests automatically using coverage and AI
Project description
AIUnitTest
AIUnitTest is a command-line tool that reads your pyproject.toml and test coverage
data (.coverage) to generate and update missing Python unit tests using AI.
Status
The current public CLI and README still describe the v1 workflow.
AIUnitTest v2 is now being defined as a redesign around a tool-first test execution layer for coding agents. It will ship first through its own CLI client and later expose the same core to external agents. The product direction is to become the specialized testing layer that works with coding agents, instead of competing with them as a general-purpose agent. The v2 planning and architecture docs live in:
docs/v2/README.mddocs/v2/architecture.mddocs/v2/implementation-plan.md
How it Works
- Coverage Analysis: The tool uses
coverage.pyto identify lines of code that are not covered by your existing test suite. - Source Code Chunking: It breaks down the source code into logical chunks (functions and classes).
- AI-Powered Test Generation: For each chunk with uncovered lines, it sends the source code and the uncovered line numbers to an AI model (like OpenAI's GPT) to generate new test cases.
- Test File Updates: The newly generated tests are appended to the corresponding test file.
Features
- Coverage Analysis: Uses the Coverage.py API to identify untested lines.
- AI-Powered Test Generation: Calls OpenAI GPT to create or enhance test cases.
- Config-Driven: Automatically picks up
coverage.run.sourceandpytest.ini_options.testpathsfrompyproject.toml. - Auto Mode: The
--autoflag sets source and tests directories without manual arguments. - Async & Parallel: Speeds up OpenAI requests for large codebases.
Installation
There are two ways to install AIUnitTest:
From PyPI
You can install the latest stable version from PyPI:
pip install AIUnitTest
Optional Dependencies
AIUnitTest supports optional features that can be installed as needed:
Basic Installation (OpenAI only)
pip install AIUnitTest
With HuggingFace Support
pip install AIUnitTest[huggingface]
With FAISS Indexing Support
pip install AIUnitTest[faiss]
All Optional Features
pip install AIUnitTest[all]
Development Dependencies
pip install AIUnitTest[dev]
You can also combine multiple extras:
pip install AIUnitTest[huggingface,faiss]
From GitHub (for the latest development version)
-
Clone the repository:
git clone https://github.com/ofido/AIUnitTest.git cd AIUnitTest
-
Install the project in editable mode:
pip install -e . # Or with optional dependencies: pip install -e .[all]
Usage
Automatic Mode
The easiest way to run the tool is in automatic mode.
It will automatically discover your source and test folders
from your pyproject.toml file.
ai-unit-test --auto
Manual Mode
You can also specify the source and test folders manually:
ai-unit-test --folders src --tests-folder tests
Generating a Test for a Specific Function
You can also generate a test for a single function:
ai-unit-test func my_module/my_file.py my_function
Indexing and Searching Tests
You can index your tests for semantic search:
ai-unit-test index
And then search for tests related to a specific query:
ai-unit-test search "my search query"
Command-Line Options
--folders: The source code folders to analyze.--tests-folder: The folder where the tests are located.--coverage-file: The path to the.coveragefile.--auto: Try to discover folders/tests frompyproject.toml.
Configuration
AIUnitTest uses the standard pyproject.toml file for configuration.
Here are the relevant sections:
[tool.coverage.run]:source: A list of source code folders.
[tool.pytest.ini_options]:testpaths: A list of test folders.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue.
License
This project is licensed under the MIT License see the LICENSE file for details.
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
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 aiunittest-0.0.8.tar.gz.
File metadata
- Download URL: aiunittest-0.0.8.tar.gz
- Upload date:
- Size: 131.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbcdd3ab79648bd27ff8581ea4fb6842516c0eaec442e8d10978e58b4717821a
|
|
| MD5 |
9580349457f2b9b466638a08fba41874
|
|
| BLAKE2b-256 |
c08528f253bd76bda867456837d0e1c25462a1c4adf3523ca7886aa38d35d895
|
Provenance
The following attestation bundles were made for aiunittest-0.0.8.tar.gz:
Publisher:
release.yml on Ofido/AIUnitTest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiunittest-0.0.8.tar.gz -
Subject digest:
fbcdd3ab79648bd27ff8581ea4fb6842516c0eaec442e8d10978e58b4717821a - Sigstore transparency entry: 1287885961
- Sigstore integration time:
-
Permalink:
Ofido/AIUnitTest@becdf3ce861c082484f6630e926c91cd62c919f8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ofido
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@becdf3ce861c082484f6630e926c91cd62c919f8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aiunittest-0.0.8-py3-none-any.whl.
File metadata
- Download URL: aiunittest-0.0.8-py3-none-any.whl
- Upload date:
- Size: 75.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3752108e3ae6f27c21939d221379e85448e51205bebb125b3c23317bd0ed195e
|
|
| MD5 |
74e9375762c5b1e414fdc24c0ab4a572
|
|
| BLAKE2b-256 |
f977c54c138eb3d68411668932be73f6626da9dab5a45ece641186fc2c1c6ed1
|
Provenance
The following attestation bundles were made for aiunittest-0.0.8-py3-none-any.whl:
Publisher:
release.yml on Ofido/AIUnitTest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiunittest-0.0.8-py3-none-any.whl -
Subject digest:
3752108e3ae6f27c21939d221379e85448e51205bebb125b3c23317bd0ed195e - Sigstore transparency entry: 1287886030
- Sigstore integration time:
-
Permalink:
Ofido/AIUnitTest@becdf3ce861c082484f6630e926c91cd62c919f8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ofido
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@becdf3ce861c082484f6630e926c91cd62c919f8 -
Trigger Event:
push
-
Statement type: