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.
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
- 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.
- 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.
There are two ways to install AIUnitTest:
You can install the latest stable version from PyPI:
pip install AIUnitTestAIUnitTest supports optional features that can be installed as needed:
pip install AIUnitTestpip install AIUnitTest[huggingface]pip install AIUnitTest[faiss]pip install AIUnitTest[all]pip install AIUnitTest[dev]You can also combine multiple extras:
pip install AIUnitTest[huggingface,faiss]-
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]
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 --autoYou can also specify the source and test folders manually:
ai-unit-test --folders src --tests-folder testsYou can also generate a test for a single function:
ai-unit-test func my_module/my_file.py my_functionYou can index your tests for semantic search:
ai-unit-test indexAnd then search for tests related to a specific query:
ai-unit-test search "my search query"--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.
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.
Contributions are welcome! Please feel free to submit a pull request or open an issue.
This project is licensed under the MIT License see the LICENSE file for details.