AIUnitTest


NameAIUnitTest JSON
Version 0.0.5 PyPI version JSON
download
home_pageNone
SummaryCLI to generate and update Python unit tests automatically using coverage and AI
upload_time2025-08-13 02:44:06
maintainerNone
docs_urlNone
authorOfido
requires_python>=3.10
licenseNone
keywords testing coverage openai automation
VCS
bugtrack_url
requirements openai coverage pytest tomli typer black isort flake8 mypy pymarkdownlnt flake8-bugbear flake8-annotations pytest pytest-cov pytest-asyncio pre-commit
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AIUnitTest

[![PyPI version](https://badge.fury.io/py/AIUnitTest.svg)](https://badge.fury.io/py/AIUnitTest)
[![Python versions](https://img.shields.io/pypi/pyversions/AIUnitTest.svg)](https://pypi.org/project/AIUnitTest)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Linter: flake8](https://img.shields.io/badge/linter-flake8-blue.svg)](https://flake8.pycqa.org/en/latest/)
[![Static typing: mypy](https://img.shields.io/badge/static%20typing-mypy-blue.svg)](https://mypy-lang.org/)
[![Testing: pytest](https://img.shields.io/badge/testing-pytest-blue.svg)](https://pytest.org)
[![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](https://coverage.readthedocs.io/)
[![CI/CD](https://github.com/ofido/AIUnitTest/actions/workflows/ci.yml/badge.svg)](https://github.com/ofido/AIUnitTest/actions/workflows/ci.yml)
[![GitHub last commit](https://img.shields.io/github/last-commit/ofido/AIUnitTest)](https://github.com/ofido/AIUnitTest/commits/main)
[![GitHub repo size](https://img.shields.io/github/repo-size/ofido/AIUnitTest)](https://github.com/ofido/AIUnitTest)
[![GitHub issues](https://img.shields.io/github/issues/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[![PyPI version](https://badge.fury.io/py/AIUnitTest.svg)](https://badge.fury.io/py/AIUnitTest)\n[![Python versions](https://img.shields.io/pypi/pyversions/AIUnitTest.svg)](https://pypi.org/project/AIUnitTest)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n[![Linter: flake8](https://img.shields.io/badge/linter-flake8-blue.svg)](https://flake8.pycqa.org/en/latest/)\n[![Static typing: mypy](https://img.shields.io/badge/static%20typing-mypy-blue.svg)](https://mypy-lang.org/)\n[![Testing: pytest](https://img.shields.io/badge/testing-pytest-blue.svg)](https://pytest.org)\n[![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](https://coverage.readthedocs.io/)\n[![CI/CD](https://github.com/ofido/AIUnitTest/actions/workflows/ci.yml/badge.svg)](https://github.com/ofido/AIUnitTest/actions/workflows/ci.yml)\n[![GitHub last commit](https://img.shields.io/github/last-commit/ofido/AIUnitTest)](https://github.com/ofido/AIUnitTest/commits/main)\n[![GitHub repo size](https://img.shields.io/github/repo-size/ofido/AIUnitTest)](https://github.com/ofido/AIUnitTest)\n[![GitHub issues](https://img.shields.io/github/issues/ofido/AIUnitTest)](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"
}
        
Elapsed time: 0.78181s