Skip to content

Parallel Execution

Run tests concurrently for faster execution.

graph TB
    subgraph "Parallel Execution"
        A[Tests] --> B[ParallelRunner]
        B --> C[Worker 1]
        B --> D[Worker 2]
        B --> E[Worker N]
        C --> F[Results]
        D --> F
        E --> F
    end

    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef runner fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class A input
    class B,C,D,E runner
    class F output

Quick Start

from testagent import run_parallel

results = run_parallel([
    ("output1", {"criteria": "is correct"}),
    ("output2", {"criteria": "is helpful"}),
    ("output3", {"expected": "4"}),
])

for result in results:
    print(f"{result.passed}: {result.score}")

ParallelRunner Class

from testagent import ParallelRunner

runner = ParallelRunner(max_workers=4)

tests = [
    {"output": "Hello", "criteria": "is a greeting"},
    {"output": "4", "expected": "4"},
]

results = runner.run(tests)

Options

Option Type Default Description
max_workers int 4 Maximum concurrent workers

Thread Safety

TestAgent is thread-safe by default:

  • Each test runs in isolation
  • No shared mutable state
  • Results are collected safely

Best Practices

When to Use Parallel

  • Many independent tests
  • Tests with similar duration
  • CI/CD pipelines

When Not to Use

  • Tests with shared resources
  • Rate-limited APIs
  • Sequential dependencies