Automatically generate comprehensive, intelligent test files for your Python projects using AI.
Features • Installation • Quick Start • Usage • Examples
|
Leverages Google Gemini to understand your code's logic, edge cases, and generate meaningful test scenarios
|
Generate tests for entire projects or directories in one command Support for both pytest and unittest frameworks with proper fixtures and assertions |
- 🎨 Clean CLI Interface - Simple, intuitive command-line tools
- � Detailed Documentation - Generates tests with inline comments
- ⚡ Fast Processing - Efficient async API calls
- 🛡️ Error Handling - Robust error detection and reporting
- 🔒 Secure - Environment-based API key management
- Python 3.8+
- Google Gemini API Key (Free tier available)
- pip package manager
git clone https://github.com/Pradyumn-cloud/Verita.git
cd Veritapip install -e .This installs the package in editable mode with all dependencies.
Get your free Gemini API key from Google AI Studio
Create a .env file in the project root:
GEMINI_API_KEY=your_api_key_heresmart-test --help# Generate test file for a Python module
smart-test generate calculator.py
# Output will be saved as test_calculator.py# Get insights about your code
smart-test analyze calculator.pyOutput shows:
- Complexity score
- Functions detected
- Recommended test strategies
- Test coverage suggestions
# Generate tests for all Python files in a directory
smart-test batch src/ -o tests/smart-test [COMMAND] [OPTIONS]| Command | Description | Example |
|---|---|---|
generate |
Generate test file for a Python source file | smart-test generate app.py |
analyze |
Analyze code without generating tests | smart-test analyze app.py |
batch |
Generate tests for all files in a directory | smart-test batch src/ |
Run Smart Test on GitHub’s runners with zero install. Results are uploaded as artifacts and can optionally be pushed as a PR.
- Add a secret GEMINI_API_KEY in your repo:
- Settings → Secrets and variables → Actions → New repository secret → Name:
GEMINI_API_KEY
- Create a workflow in your repo:
name: Smart Test Generator
on:
workflow_dispatch:
inputs:
paths:
description: "Path(s) to scan (e.g., src/ or app.py)"
required: true
default: "src/**/*.py"
jobs:
generate-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Generate AI Tests
uses: Pradyumn-cloud/Verita@v4.0.3
with:
paths: ${{ inputs.paths }}
gemini-api-key: ${{ secrets.GEMINI_API_KEY }}
# model: "models/gemini-2.0-flash" # optional (default)
# framework: "pytest" # optional (default)
# output-dir: "generated-tests" # optional (default)
- name: Upload Generated Tests
uses: actions/upload-artifact@v4
with:
name: ai-generated-tests
path: generated-tests/The action intelligently handles all these input patterns:
| Scenario | Example Input | Result |
|---|---|---|
| Single File | app.py |
Generates test_app.py |
| Single Directory | src/ |
Generates tests for all .py files in src/ (recursive) |
| Multiple Files | app.py,utils.py,config.py |
Generates 3 separate test files |
| Multiple Directories | src/,lib/,tests/helpers/ |
Processes all Python files in each directory |
| Mixed Paths | app.py,src/models/,lib/utils.py |
Handles both files and directories together |
| Nested Directories | src/models/user/ |
Recursively finds all Python files in subdirectories |
Workflow Examples:
# Example 1: Single Python file
- uses: Pradyumn-cloud/Verita@v4.0.3
with:
paths: 'calculator.py'
gemini-api-key: ${{ secrets.GEMINI_API_KEY }}
# Example 2: Entire directory (recursive)
- uses: Pradyumn-cloud/Verita@v4.0.3
with:
paths: 'src/'
gemini-api-key: ${{ secrets.GEMINI_API_KEY }}
# Example 3: Multiple specific files (comma-separated, NO SPACES)
- uses: Pradyumn-cloud/Verita@v4.0.3
with:
paths: 'app.py,utils.py,config.py'
gemini-api-key: ${{ secrets.GEMINI_API_KEY }}
# Example 4: Multiple directories
- uses: Pradyumn-cloud/Verita@v4.0.3
with:
paths: 'src/,lib/,tests/helpers/'
gemini-api-key: ${{ secrets.GEMINI_API_KEY }}
# Example 5: Mix of files and directories
- uses: Pradyumn-cloud/Verita@v4.0.3
with:
paths: 'main.py,src/models/,lib/utils.py'
gemini-api-key: ${{ secrets.GEMINI_API_KEY }}- Use commas without spaces to separate paths: ✅
src/,lib/❌src/, lib/ - Directories are processed recursively (all subdirectories included)
- Only
.pyfiles are processed; other files are automatically skipped - Output files are named
test_<original_filename>.py
Required:
GEMINI_API_KEYsecret must be configured in repository settings- Get your FREE API key at: https://aistudio.google.com/app/apikey
Permissions:
- Standard GitHub Actions permissions are sufficient
- No special repository permissions needed
This repo includes example workflows you can test:
- Go to the Actions tab
- Select "Smart Test Generator" workflow
- Click "Run workflow"
- Enter paths (try:
examples/calculator.pyorexamples/) - Click "Run workflow" button
- Wait for completion and download the
ai-generated-testsartifact
You can test all these scenarios:
examples/calculator.py- Single fileexamples/- Entire directorysmart_test/analyzer.py,smart_test/generator.py- Multiple files
Generate a comprehensive test file for your Python code:
# Basic usage
smart-test generate mymodule.py
# Specify output location
smart-test generate mymodule.py -o tests/test_mymodule.py
# Choose unittest framework
smart-test generate mymodule.py -f unittest
# Generate template without AI
smart-test generate mymodule.py --no-ai
# Verbose output
smart-test generate mymodule.py -vOptions:
-o, --output PATH- Specify custom output file path-f, --framework {pytest|unittest}- Choose test framework (default: pytest)--no-ai- Generate basic template without AI analysis-k, --api-key KEY- Provide API key directly (overrides .env)-v, --verbose- Enable detailed logging
Analyze your code structure and get test recommendations:
smart-test analyze mymodule.pyOutput includes:
- Cyclomatic complexity score
- List of functions and classes
- Recommended test strategies
- Edge cases to consider
Generate tests for multiple files:
# Process entire directory
smart-test batch src/ -o tests/
# Specific framework for all files
smart-test batch src/ -o tests/ -f unittest
# Verbose batch processing
smart-test batch src/ -o tests/ -v# examples/calculator.py
def add(a, b):
return a + b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / bGenerate tests:
smart-test generate examples/calculator.pyGenerated test file includes:
- ✅ Basic functionality tests
- ✅ Edge case tests (division by zero)
- ✅ Type validation tests
- ✅ Proper fixtures and assertions
# examples/mypackage/string_utils.py
def reverse_string(s):
return s[::-1]
def is_palindrome(s):
return s == s[::-1]Generate with analysis:
smart-test analyze examples/mypackage/string_utils.py
smart-test generate examples/mypackage/string_utils.py -o tests/test_string_utils.pyVerita/
├── smart_test/ # Main package
│ ├── __init__.py
│ ├── cli.py # CLI interface
│ ├── generator.py # Test generation logic
│ ├── analyzer.py # Code analysis
│ ├── llm_client.py # Gemini API client
│ ├── models.py # Data models
│ ├── config.py # Configuration
│ └── utils.py # Utilities
├── examples/ # Example files
│ ├── calculator.py
│ └── mypackage/
├── setup.py # Package setup
├── .env # API key (not tracked)
├── .gitignore # Git ignore rules
└── README.md # This file
Create a .env file in the project root:
# Required
GEMINI_API_KEY=your_actual_api_key_here
# Optional (with defaults)
GEMINI_MODEL=models/gemini-2.0-flash
MAX_RETRIES=3
TIMEOUT=30You can override settings via command-line options or modify smart_test/config.py.
Contributions are welcome! Please feel free to submit issues or pull requests.
# Clone the repository
git clone https://github.com/Pradyumn-cloud/Verita.git
cd Verita
# Install in development mode
pip install -e .
# Run examples
smart-test generate examples/calculator.pyIssue: ModuleNotFoundError: No module named 'smart_test'
- Solution: Run
pip install -e .in the project root
Issue: API key not found
- Solution: Ensure
.envfile exists with validGEMINI_API_KEY
Issue: Rate limit exceeded
- Solution: Wait a few moments and retry, or check your API quota
Issue: Tests not generating
- Solution: Run with
-vflag for verbose output to see error details
MIT © 2025 Pradyumn. See the LICENSE file for details.
- Google Gemini - For powering the AI test generation
- Python Community - For amazing testing frameworks
- Open Source Contributors - For inspiration and tools
Author: Pradyumn
GitHub: @Pradyumn-cloud
Project: Verita
⭐ Star this repo if you find it helpful! ⭐
Made by Pradyumn
