Test Without Framework

Hypergraph nodes are pure functions. Test them directly — no framework setup, no mocking.

The Core Pattern

Every node has a .func attribute that gives you the raw function:

@node(output_name="result")
def process(text: str) -> str:
    return text.upper()

# Test the function directly
def test_process():
    result = process.func("hello")
    assert result == "HELLO"

Why This Works

The @node decorator adds metadata (inputs, outputs, name) but doesn't change the function's behavior:

@node(output_name="doubled")
def double(x: int) -> int:
    return x * 2

# These are equivalent:
double(5)       # Call through the node wrapper → 10
double.func(5)  # Call the raw function → 10

Testing Patterns

Unit Test a Single Node

Test with Mocked Dependencies

Test Async Nodes

Test Multiple Outputs

Testing Graphs

Test Graph Construction

Test Graph Execution

Test with Fixtures

Testing Routing Logic

Property-Based Testing

Use hypothesis for thorough testing:

Snapshot Testing

For complex outputs, use snapshot testing:

Benefits

  1. Fast — No graph construction or runner overhead

  2. Isolated — Test one function at a time

  3. Simple — Standard pytest patterns work

  4. Debuggable — Step through your function directly

What's Next?

Last updated