Haiku

Python

Plain-English Python tests. .py.haiku files compile to pytest modules and run via pytest.

Status: available

.py.haiku files describe what a Python module or function should do in plain English. Haiku compiles them to standard pytest modules (test_*.py) and runs them through pytest.

Filename

<base>.py.haiku — e.g. test_parser.py.haiku, user_service.py.haiku. The generated test file is named test_<base>.py and is written next to the spec.

Frontmatter

---
intent: Verifies the user service correctly creates and retrieves users
sources:
  - ../src/services/user_service.py
tags: [users]
---
FieldRequiredNotes
intentyesOne-line description
sourcesrecommendedOrdered list of source files the test exercises, most-called first
target.modulenoLegacy dotted module path (e.g. services.user_service)
target.contextnoExtra module paths to feed the compiler

Body

One natural-English assertion per line. Phrasings like "X returns Y", "X raises Z", "X is recognised as W" all work — Haiku's backend compiler keeps the grammar loose.

A new user is created with a unique id.
Looking up an unknown user id returns None.
Creating a user with an empty email raises ValueError.
The user's created_at timestamp is set to the current UTC time.

Running

haiku recite test_parser.py.haiku

On the first run Haiku compiles to test_test_parser.py and runs pytest on it. On subsequent runs the generated file is reused unless the spec changes or you pass --fresh.

Requirements

  • pytest available on PATH (or pre-installed in the venv Haiku launches in)
  • A pyproject.toml or setup.py ancestor of the spec (so pytest's import-mode resolves your source tree)

On this page