AI-native test case generation framework using dependency graphs.
TestWeaver is a modern rework of depend-test-framework, redesigned to be AI-native and agent-friendly. Define test operations with decorators in Python (or declaratively in YAML), and TestWeaver builds a dependency graph to automatically discover all valid test paths.
Core
- Decorator-based definitions —
@provides,@requires,@clears,@excludes,@graft,@cut - Hierarchical state model — states are trees (
vm.config.tpm) - Automatic case generation — dependency graph finds all valid paths to each target
- Runtime data flow — operations pass dynamic data (UUIDs, IPs) through
envnode values - Operation verification —
@verify_for/verifyYAML field - Graph modifiers —
EdgeGuard,TransientHook,TransitionObserverfor runtime decisions
Parameterization
- Parameter graph (
param_choices) — parameters affect which operations are available - Parameter matrix (
param_matrix) — Cartesian product with constraint filtering - Multi-instance namespaces —
TPM:tpm0,TPM:tpm1with wildcard queries and generation strategies
Execution
- Parallel execution —
--workers Nfor concurrent test cases - Retry / flaky handling —
--retrieswith automatic flaky detection - Per-step timeout —
@timeout(seconds)per operation - Lifecycle hooks —
@suite_setup,@suite_teardown,@case_setup,@case_teardown - Dry-run mode —
--dry-runto preview without executing
Output & Analysis
- Structured reporting — JSON, JUnit XML, TAP, HTML
- Graph visualization — DOT (Graphviz) and Mermaid export
- Case filtering —
-k,--target,--has-step,--fault-only - Case prioritization —
--sort shortest|longest|target|total|fault-first|random - Progress reporting — live progress bar with
--progress - Logging —
--verbose,--debug,--log-file
Assertions
- Fluent assertion API —
assert_that(value).equals(expected).greater_than(0) - Chained assertions with rich expected-vs-actual diffs
assert_raisescontext manager for exception testing
pip install -e ".[dev]"# my_ops.py
from testweaver import action, check, cleanup, provides, requires, clears, verify_for
@action
@provides('file.exists')
def create_file(params, env):
import subprocess
subprocess.run('echo "hello world" > /tmp/test.txt', shell=True, check=True)
@verify_for('create_file')
def check_content(params, env):
import subprocess
subprocess.run('grep -q "hello world" /tmp/test.txt', shell=True, check=True)
@check
@requires('file.exists')
def check_file_exists(params, env):
import subprocess
subprocess.run('test -f /tmp/test.txt', shell=True, check=True)
@cleanup
@requires('file.exists')
@clears('file.exists')
def remove_file(params, env):
import subprocess
subprocess.run('rm -f /tmp/test.txt', shell=True, check=True)testweaver run my_ops.py --format textoperations:
- name: create_file
type: action
provides: [file.exists]
run: echo "hello world" > /tmp/hello.txt
verify: grep -q "hello world" /tmp/hello.txt
- name: check_file_exists
type: check
requires: [file.exists]
run: test -f /tmp/hello.txt
- name: remove_file
type: cleanup
requires: [file.exists]
clears: [file.exists]
run: rm -f /tmp/hello.txt
suite:
name: "Hello World"
targets: [check_file_exists]
cleanup: truetestweaver validate my_test.yaml # Check for errors
testweaver generate my_test.yaml # Generate test cases
testweaver run my_test.yaml # Run tests (JSON output)
testweaver run my_test.yaml --format text # Human-readable output
testweaver graph my_test.yaml --format dot | dot -Tpng -o graph.png # Visualize| Document | Description |
|---|---|
| Getting Started | Tutorial: build your first test suite step by step |
| Core Concepts | Operations, states, dependency graph, modifiers, parameters |
| CLI Reference | All commands and flags |
| Topic | Description |
|---|---|
| Parameters | Parameter graph and matrix |
| Multi-Instance | Multiple devices with independent states |
| Verification | Operation verification callbacks |
| Graph Modifiers | EdgeGuard, TransientHook, TransitionObserver |
| Graph Visualization | DOT and Mermaid export |
| Filtering | Select test case subsets |
| Prioritization | Sort cases by strategy |
| Dry-Run | Preview without executing |
| Scalability | Graph size and path depth controls |
| Reporting | JUnit XML, TAP, HTML output |
| Retry | Retry and flaky test handling |
| Logging | Logging configuration |
| Progress | Progress bar and callbacks |
| Lifecycle Hooks | Suite and case setup/teardown |
| Data Flow | Passing runtime data between operations |
| Assertions | Fluent assertion API with chaining and diffs |
| Virtualization | libvirt/QEMU example modules |
The examples/virt/ directory contains mock implementations of libvirt/QEMU test operations (VM lifecycle, vTPM, save/restore, disk management, and more). See Virtualization Examples.
testweaver generate examples/virt/vtpm_test.yaml --format text
testweaver run examples/virt/backing_chain_test.yaml --format textTestWeaver is designed to be used by AI agents:
- Get the schema:
testweaver schema --type definitionreturns the JSON Schema - Generate a definition: Write a YAML file matching the schema
- Validate:
testweaver validate <file>checks for errors - Run:
testweaver run <file> --output results.jsonreturns structured results - Debug:
testweaver analyze results.json -d <file>provides failure details
All commands output JSON by default.
MIT