Skip to main content

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:

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 execution
  • examples/kedro/ - Testing Kedro project scaffolding

Running an Example

  1. Navigate to an example directory:
cd examples/dlt
  1. 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:

  1. Install dlt in a temporary virtual environment
  2. Configure Claude Code with the specified CLI options
  3. Ask Claude to create the dlt project
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doctest_ai-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

doctest_ai-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

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

Hashes for doctest_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dd15af8a69fa90d3dce88287384abba0af95336f70ea2b351c9ce9fc766e9811
MD5 adcb4839e437a2c49a5d5159065ebab8
BLAKE2b-256 a5263d130da385b1d92c0c55992de854b9ba16b7e222d10d981f7cdf72f17b8e

See more details on using hashes here.

File details

Details for the file doctest_ai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for doctest_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cea9ae1a3ec490401af348b23ebb3bb26b32d9f802edd96891dd9690f1a0b1e7
MD5 f335b76f316a52511c9d39697ae58fd0
BLAKE2b-256 297f5f67335293c9812016dbbd178a3becd6866efae0a371a9cf2358094d3c47

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page