Skip to main content

TestCases Writer AI Tool

Automatically generate comprehensive pytest test cases for your Python application using Claude AI.

Features

  • Scans your Python project and sends code to Claude AI to generate high-quality pytest test cases.
  • Smart caching: Only makes API calls when your code has actually changed, saving costs and time.
  • Writes the generated tests to a tests/ directory in your project.
  • Ensures test files are import-safe by patching sys.path.
  • Supports file-based storage patching for isolated tests (see advanced usage).

Requirements

  • Python 3.7+
  • Anthropic Claude API key
  • Internet connection (for API calls)
  • Packages in requirements.txt (install with pip install -r requirements.txt)

Installation

  1. Clone this repository (or copy the tool files):

    git clone <your-repo-url>
    cd TestCases_Writer_AI_Tool
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set your Anthropic API key:

    export ANTHROPIC_API_KEY=sk-ant-...
    

Usage

  1. Run the tool on your Python app:

    generate-test-cases /path/to/your/python/app
    
    • Replace /path/to/your/python/app with the path to the root of your Python project.
    • The tool will scan all .py files, send them to Claude, and write generated tests to a tests/ directory inside your app.
  2. Run the generated tests:

    cd /path/to/your/python/app
    pytest
    

How It Works

  • The tool collects all Python files in your app.
  • Smart caching: Before making API calls, it checks if any files have changed since the last run by comparing file hashes and modification times. If no changes are detected, it skips the API call to save costs.
  • It sends the code to Claude AI with a prompt to generate pytest-style tests.
  • The generated tests are written to tests/test_generated.py (or one test file per source file).
  • Each test file includes a snippet to patch sys.path for import safety.
  • A .test_generator_cache file is created in your app directory to track file changes.

Advanced: Isolating File-Based Storage in Tests

If your app uses a file (like tasks.json) for storage, the tool can generate a pytest fixture to patch the storage path using tmp_path and monkeypatch. This ensures each test runs in isolation and avoids data leakage between tests.

Example fixture (auto-included if detected):

import pytest

@pytest.fixture
def temp_tasks_file(tmp_path, monkeypatch):
    temp_file = tmp_path / "tasks.json"
    monkeypatch.setattr("notes_app.storage.TASKS_FILE", str(temp_file))
    return str(temp_file)

Troubleshooting

  • ModuleNotFoundError:
    Make sure you run pytest from your project root, and that the generated test files include the sys.path patch at the top.
  • API Errors:
    Ensure your ANTHROPIC_API_KEY is set and valid.
  • No tests generated:
    Check that your app directory contains .py files and is accessible.
  • Tool says "no changes detected" but you want to regenerate:
    Delete the .test_generator_cache file in your app directory and run the tool again.

License

MIT License


Credits

Metadata

Release files for testcases-writer-ai-tool 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for testcases-writer-ai-tool 0.1.0
File Size Uploaded Provenance
testcases_writer_ai_tool-0.1.0.tar.gz 6.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for testcases-writer-ai-tool 0.1.0
File Interpreter ABI Platform
testcases_writer_ai_tool-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / testcases_writer_ai_tool-0.1.0.tar.gz

Download URL testcases_writer_ai_tool-0.1.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f5b98c50d8a5a8f1e1c93629a392af0d1313c1f1872f08256576561df21a13fb
BLAKE2b-256 checksum
How to use checksums
538be9b51fc683e05132ac6efad36ec35c54c4a5c6b4dcfebc829ca8fe5522a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / testcases_writer_ai_tool-0.1.0-py3-none-any.whl

Download URL testcases_writer_ai_tool-0.1.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3596bc2c230cbeb5cd55944eb3a8ba5fc58a13651d26797d12a77aa221bbd53
BLAKE2b-256 checksum
How to use checksums
7316abca1fb35c22d5833de463ddf62f897bd605d692ae5044f2bfbb8f57f476
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Security for testcases-writer-ai-tool 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page