A pytest plugin that enables testing agentic coding workflows using pytest-bdd.
Project description
doctest-ai
A pytest plugin that enables testing agentic coding workflows using pytest-bdd.
What is doctest-ai?
doctest-ai allows you to write behavioral tests in natural language using Gherkin syntax (.feature files), and have a coding agent execute the When step. This is particularly useful for:
- Testing AI-assisted code generation workflows
- Validating that AI can correctly implement framework-specific tasks
doctest-ai is intended for testing agentic coding workflows, not for automating testing workflows using AI. You need to define the initial context (Given steps) and expected outcome (Then steps).
Prerequisites
Before using doctest-ai, ensure you have the following tools installed on your system:
- Claude Code: https://code.claude.com/docs/en/setup
- uv: https://docs.astral.sh/uv/getting-started/installation/
Installation
Install doctest-ai from PyPI using uv or pip:
uv pip install doctest-ai
or
pip install doctest-ai
Quickstart
The examples/ folder contains several working examples that demonstrate how to use doctest-ai:
Available Examples
examples/dlt/- Testing dlt project creation and executionexamples/kedro/- Testing Kedro project scaffolding
Running an Example
- Navigate to an example directory:
cd examples/dlt
- Run the test with pytest:
pytest test_init.py
Example: dlt Project Creation
The examples/dlt/init.feature file defines a test scenario:
Feature: New dlt project
Background:
Given I have installed dlt
Scenario: Create a new dlt project
Given I have configured the following CLI options in Claude Code:
| allowed_tools | Write,Bash(python pokemon_pipeline.py:*),Edit |
When I ask Claude to create a dlt project with a single pipeline that loads data from the Pokemon API and stores it in a local directory
Then the pipeline runs successfully
The corresponding test_init.py implements the "Then" step:
from doctest_ai.sh_run import run
from pytest_bdd import given, parsers, scenario, then
OK_EXIT_CODE = 0
@scenario("init.feature", "Create a new dlt project")
def test_init():
pass
@given(parsers.parse("I have installed {package}"))
def install_package(request, package):
"""Install the specified package."""
run(["uv", "pip", "install", package], check=True, env=request.env)
@then("the pipeline runs successfully")
def run_pipeline(request, tmp_path):
res = run(["python", "pokemon_pipeline.py"], cwd=tmp_path, env=request.env)
assert res.returncode == OK_EXIT_CODE, res
When you run pytest test_init.py, the test will:
- Install dlt in a temporary virtual environment
- Configure Claude Code with the specified CLI options
- Ask Claude to create the dlt project
- Verify the pipeline runs successfully
Configuration
Project Settings
You can configure doctest-ai behavior through pyproject.toml (under the [tool.doctest-ai] section):
max_retries: Number of times to retry if a test fails (enables agentic loop)
Claude Code Settings
You can specify Claude Code options for your project in pyproject.toml (under the [tool.doctest-ai.claude-code] section):
[tool.doctest-ai.claude-code]
model = "claude-3-7-sonnet-20250219"
You can also configure Claude Code options in your test scenarios using the Given step:
Given I have configured the following CLI options in Claude Code:
| allowed_tools | Write,Bash,Edit |
| model | sonnet |
Configuration at the scenario level overrides overlapping configuration at the project level.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file doctest_ai-0.1.0.tar.gz.
File metadata
- Download URL: doctest_ai-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd15af8a69fa90d3dce88287384abba0af95336f70ea2b351c9ce9fc766e9811
|
|
| MD5 |
adcb4839e437a2c49a5d5159065ebab8
|
|
| BLAKE2b-256 |
a5263d130da385b1d92c0c55992de854b9ba16b7e222d10d981f7cdf72f17b8e
|
File details
Details for the file doctest_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: doctest_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cea9ae1a3ec490401af348b23ebb3bb26b32d9f802edd96891dd9690f1a0b1e7
|
|
| MD5 |
f335b76f316a52511c9d39697ae58fd0
|
|
| BLAKE2b-256 |
297f5f67335293c9812016dbbd178a3becd6866efae0a371a9cf2358094d3c47
|