# AIUnitTest
[](https://badge.fury.io/py/AIUnitTest)
[](https://pypi.org/project/AIUnitTest)
[](https://opensource.org/licenses/MIT)
[](https://github.com/psf/black)
[](https://pycqa.github.io/isort/)
[](https://flake8.pycqa.org/en/latest/)
[](https://mypy-lang.org/)
[](https://pytest.org)
[](https://coverage.readthedocs.io/)
[](https://github.com/ofido/AIUnitTest/actions/workflows/ci.yml)
[](https://github.com/ofido/AIUnitTest/commits/main)
[](https://github.com/ofido/AIUnitTest)
[](https://github.com/ofido/AIUnitTest/issues)
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.
## How it Works
1. **Coverage Analysis**: The tool uses `coverage.py` to identify lines of code
that are not covered by your existing test suite.
2. **Source Code Chunking**: It breaks down the source code into logical chunks
(functions and classes).
3. **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.
4. **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.source` and
`pytest.ini_options.testpaths` from `pyproject.toml`.
- **Auto Mode**: The `--auto` flag 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:
```bash
pip install AIUnitTest
```
### From GitHub (for the latest development version)
1. **Clone the repository:**
```bash
git clone https://github.com/ofido/AIUnitTest.git
cd AIUnitTest
```
2. **Install the project in editable mode:**
```bash
pip install -e .
```
## 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.
```bash
ai-unit-test --auto
```
### Manual Mode
You can also specify the source and test folders manually:
```bash
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:
```bash
ai-unit-test func my_module/my_file.py my_function
```
### 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 `.coverage` file.
- `--auto`: Try to discover folders/tests from `pyproject.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](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "AIUnitTest",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "testing, coverage, openai, automation",
"author": "Ofido",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/d9/a5/e0d15d934382ddfe5b30289edb2e63e343bbd301fe698e71bd9fc609ae37/aiunittest-0.0.5.tar.gz",
"platform": null,
"description": "# AIUnitTest\n\n[](https://badge.fury.io/py/AIUnitTest)\n[](https://pypi.org/project/AIUnitTest)\n[](https://opensource.org/licenses/MIT)\n[](https://github.com/psf/black)\n[](https://pycqa.github.io/isort/)\n[](https://flake8.pycqa.org/en/latest/)\n[](https://mypy-lang.org/)\n[](https://pytest.org)\n[](https://coverage.readthedocs.io/)\n[](https://github.com/ofido/AIUnitTest/actions/workflows/ci.yml)\n[](https://github.com/ofido/AIUnitTest/commits/main)\n[](https://github.com/ofido/AIUnitTest)\n[](https://github.com/ofido/AIUnitTest/issues)\n\nAIUnitTest is a command-line tool that reads your `pyproject.toml` and test coverage\ndata (`.coverage`) to generate and update missing Python unit tests using AI.\n\n## How it Works\n\n1. **Coverage Analysis**: The tool uses `coverage.py` to identify lines of code\n that are not covered by your existing test suite.\n2. **Source Code Chunking**: It breaks down the source code into logical chunks\n (functions and classes).\n3. **AI-Powered Test Generation**: For each chunk with uncovered lines,\n it sends the source code and the uncovered line numbers to an AI model\n (like OpenAI's GPT) to generate new test cases.\n4. **Test File Updates**: The newly generated tests are appended to the\n corresponding test file.\n\n## Features\n\n- **Coverage Analysis**: Uses the Coverage.py API to identify untested lines.\n- **AI-Powered Test Generation**: Calls OpenAI GPT to create or enhance test cases.\n- **Config-Driven**: Automatically picks up `coverage.run.source` and\n `pytest.ini_options.testpaths` from `pyproject.toml`.\n- **Auto Mode**: The `--auto` flag sets source and tests directories without\n manual arguments.\n- **Async & Parallel**: Speeds up OpenAI requests for large codebases.\n\n## Installation\n\nThere are two ways to install AIUnitTest:\n\n### From PyPI\n\nYou can install the latest stable version from PyPI:\n\n```bash\npip install AIUnitTest\n```\n\n### From GitHub (for the latest development version)\n\n1. **Clone the repository:**\n\n ```bash\n git clone https://github.com/ofido/AIUnitTest.git\n cd AIUnitTest\n ```\n\n2. **Install the project in editable mode:**\n\n ```bash\n pip install -e .\n ```\n\n## Usage\n\n### Automatic Mode\n\nThe easiest way to run the tool is in automatic mode.\nIt will automatically discover your source and test folders\nfrom your `pyproject.toml` file.\n\n```bash\nai-unit-test --auto\n```\n\n### Manual Mode\n\nYou can also specify the source and test folders manually:\n\n```bash\nai-unit-test --folders src --tests-folder tests\n```\n\n### Generating a Test for a Specific Function\n\nYou can also generate a test for a single function:\n\n```bash\nai-unit-test func my_module/my_file.py my_function\n```\n\n### Command-Line Options\n\n- `--folders`: The source code folders to analyze.\n- `--tests-folder`: The folder where the tests are located.\n- `--coverage-file`: The path to the `.coverage` file.\n- `--auto`: Try to discover folders/tests from `pyproject.toml`.\n\n## Configuration\n\nAIUnitTest uses the standard `pyproject.toml` file for configuration.\nHere are the relevant sections:\n\n- **`[tool.coverage.run]`**:\n - `source`: A list of source code folders.\n- **`[tool.pytest.ini_options]`**:\n - `testpaths`: A list of test folders.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue.\n\n## License\n\nThis project is licensed under the MIT License\nsee the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": null,
"summary": "CLI to generate and update Python unit tests automatically using coverage and AI",
"version": "0.0.5",
"project_urls": {
"Bug Tracker": "https://github.com/ofido/AIUnitTest/issues",
"Homepage": "https://github.com/ofido/AIUnitTest"
},
"split_keywords": [
"testing",
" coverage",
" openai",
" automation"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ef922e3af1d948bb8b97899665e0a762959b247171c0534ecf1163f670c729ab",
"md5": "d44b2620474a72535e9035aa7d53eaca",
"sha256": "f911760cbf91cc2b08d3d62e3b783bccdd3f8061811975ee380f468a3c15f1b9"
},
"downloads": -1,
"filename": "aiunittest-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d44b2620474a72535e9035aa7d53eaca",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 15296,
"upload_time": "2025-08-13T02:44:05",
"upload_time_iso_8601": "2025-08-13T02:44:05.156261Z",
"url": "https://files.pythonhosted.org/packages/ef/92/2e3af1d948bb8b97899665e0a762959b247171c0534ecf1163f670c729ab/aiunittest-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "d9a5e0d15d934382ddfe5b30289edb2e63e343bbd301fe698e71bd9fc609ae37",
"md5": "21e993475424aeee4250d6706cbc4186",
"sha256": "6d99f6ba5fba58deee198e5d051352386ad51c822bf149c3469d0e03d772c0cf"
},
"downloads": -1,
"filename": "aiunittest-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "21e993475424aeee4250d6706cbc4186",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 32570,
"upload_time": "2025-08-13T02:44:06",
"upload_time_iso_8601": "2025-08-13T02:44:06.463280Z",
"url": "https://files.pythonhosted.org/packages/d9/a5/e0d15d934382ddfe5b30289edb2e63e343bbd301fe698e71bd9fc609ae37/aiunittest-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-13 02:44:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ofido",
"github_project": "AIUnitTest",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "openai",
"specs": []
},
{
"name": "coverage",
"specs": []
},
{
"name": "pytest",
"specs": []
},
{
"name": "tomli",
"specs": []
},
{
"name": "typer",
"specs": []
},
{
"name": "black",
"specs": []
},
{
"name": "isort",
"specs": []
},
{
"name": "flake8",
"specs": []
},
{
"name": "mypy",
"specs": []
},
{
"name": "pymarkdownlnt",
"specs": []
},
{
"name": "flake8-bugbear",
"specs": []
},
{
"name": "flake8-annotations",
"specs": []
},
{
"name": "pytest",
"specs": []
},
{
"name": "pytest-cov",
"specs": []
},
{
"name": "pytest-asyncio",
"specs": []
},
{
"name": "pre-commit",
"specs": []
}
],
"lcname": "aiunittest"
}