Skip to content

docs(testing): add testing guide and runnable example (#1044)#1573

Open
Hore01 wants to merge 1 commit intoapache:mainfrom
Hore01:docs/issue-1044-testing-guide
Open

docs(testing): add testing guide and runnable example (#1044)#1573
Hore01 wants to merge 1 commit intoapache:mainfrom
Hore01:docs/issue-1044-testing-guide

Conversation

@Hore01
Copy link
Copy Markdown

@Hore01 Hore01 commented May 6, 2026

This adds a User Guide page on testing Hamilton code, plus a small
runnable example folder. Between them they cover the four cases in
#1044: unit-testing plain functions, unit-testing functions that use
@tag / @parameterize / @extract_columns, integration-testing with
inputs= and overrides=, and building a Hamilton module inline inside
a test using ad_hoc_utils.create_temporary_module — the same pattern
the Hamilton test suite uses for custom materializers.

Closes #1044.

The new docs page is docs/how-tos/test-hamilton-code.rst. I slotted
it into the User Guide toctree between run-data-quality-checks and
use-hamilton-for-lineage. Every code block on the page is a
.. literalinclude:: pulled from the new examples/testing/ folder,
so future changes to the example will flow into the docs without a
second edit.

I tested locally on Python 3.12: pytest examples/testing/ passes
all 13 tests, and ruff check / ruff format --check are clean.
Sphinx (-b dirhtml) builds cleanly too, and no warnings reference
any of the new files. The 41 warnings I do see locally are the
autodoc warnings about optional plugin deps (dask, polars, pyspark,
mlflow, etc.) that are already present on main; CI installs the full
docs dependency group so they resolve there.

A few small notes:

  • I went with the long-form ASF Apache 2.0 header on the new Python
    files since that's what the rest of the repo uses. Happy to switch
    to a shorter SPDX line if that's preferred for new files.
  • No new dependencies; the example only uses apache-hamilton, pandas,
    and pytest.
  • Commit is DCO-signed.

Hamilton's DAG model is the backbone of clean ETL, and tests are how that
backbone stays honest. This adds a canonical guide and a runnable example
that cover the four scenarios called out in apache#1044:

  1. Unit-testing plain Hamilton functions
  2. Unit-testing functions that use decorators (@tag, @parameterize,
     @extract_columns) -- both by calling the underlying callable and by
     building a Driver to verify the decorator wiring
  3. Integration-testing the DAG with `Builder().with_modules(...).build()`,
     including `inputs=` and `overrides=` for short-circuiting upstream nodes
  4. Driving an in-memory module via `ad_hoc_utils.create_temporary_module`
     for self-contained tests (e.g. of custom materializers)

The docs page at `docs/how-tos/test-hamilton-code.rst` uses
`.. literalinclude::` to pull every snippet from `examples/testing/`, so the
guide and the example cannot drift out of sync.

Closes apache#1044

Signed-off-by: Olajumoke Akinremi <106763970+Hore01@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add documentation & example on writing tests for Hamilton code

1 participant