A modern Python framework that auto-generates pytest test cases and optionally an Excel test case sheet from plain English requirements using LLMs. Supports both OpenAI API and Ollama local models, configurable via config.ini
.
- 📄 Natural language → Tests: Write your acceptance criteria in
criteria/criterion.txt
, and let the framework generate pytest code. - 📊 Excel export: Optionally generate a structured Excel file (
.xlsx
) with test case rows (Test Name
,Description
,Steps
,Expected
, etc.). - 🔄 Flexible LLM backend: Choose between OpenAI (cloud) or Ollama (local) from
config.ini
. - ⚙️ Config-driven: All keys, models, and provider settings live in
config.ini
(no env vars needed). - 🛡️ Safe defaults: Deterministic generation (temperature=0), code-only outputs, and syntax validation.
- 🔁 Fallbacks: Optionally switch to a backup provider if the primary one fails.
testgen-openai/
├─ criteria/ # Requirement specs in plain text
│ └─ criterion.txt # Write your acceptance criteria here
├─ testgen/ # Core framework
│ ├─ __init__.py
│ ├─ reader.py
│ ├─ prompt.py
│ ├─ config_loader.py
│ ├─ openai_client.py
│ ├─ ollama_client.py
│ ├─ llm_router.py # Provider selection logic
│ ├─ excel_writer.py # Excel export module
│ └─ generator.py
├─ tests/
│ ├─ test_generated.py # Auto-generated tests (do not edit)
│ └─ test_cases.xlsx # Optional Excel test cases
├─ config.ini # All settings (provider, API keys, models, export flag)
├─ requirements.txt
└─ run_generate.py # CLI entrypoint
git clone <your-repo-url> aitestgen
cd aitestgen
python -m venv .venv
source .venv/bin/activate # mac/linux
.\.venv\Scripts\activate # windows
pip install -r requirements.txt
Edit config.ini
:
[llm]
provider = openai # or ollama
fallback_enabled = true
fallback_provider = ollama
[openai]
api_key = sk-...
model = gpt-3.5-turbo
[ollama]
host = http://localhost:11434
model = gemma3:4b
[export]
excel = true # enable Excel export
excel_path = tests/test_cases.xlsx
Put your acceptance criteria in criteria/criterion.txt
, for example:
1. Login: Valid credentials should sign in the user and redirect to the dashboard within 3 seconds.
2. Login: Incorrect password should display the message "Invalid email or password." without revealing which field is wrong.
3. Signup: Password must meet strength rules (≥8 chars, uppercase, lowercase, number, special character).
...
A longer sample file is already included with 15 UI acceptance criteria.
python run_generate.py --criterion criteria/criterion.txt
Generated artifacts:
- ✅
tests/test_generated.py
(pytest tests) - 📊
tests/test_cases.xlsx
(Excel test sheet, if enabled)
pytest -q
- To use OpenAI: set
[llm] provider=openai
and fill[openai] api_key
. - To use Ollama: set
[llm] provider=ollama
and ensure Ollama server is running (ollama serve
). - You can enable automatic fallback in
config.ini
.
- 🧩 Prompt design lives in
testgen/prompt.py
— tweak it to change generation style. - ✅ Generated code is syntax-checked before writing.
- 🧪 Supports
pytest.raises
for exceptions. - 📊 Excel export uses
openpyxl
— lightweight and configurable. - 🔒 API keys are never hard-coded — only read from
config.ini
.
MIT — free to use, modify, and share.
- OpenAI for API access.
- Ollama for local LLMs.
- pytest for a clean testing experience.
- openpyxl for Excel generation.
🚧 Tip: Review generated tests before committing them to production. LLMs may make assumptions about imports or edge cases.