Skip to content

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

Merged
skrawcz merged 1 commit into
apache:mainfrom
Hore01:docs/issue-1044-testing-guide
May 11, 2026
Merged

docs(testing): add testing guide and runnable example (#1044)#1573
skrawcz merged 1 commit into
apache:mainfrom
Hore01:docs/issue-1044-testing-guide

Conversation

@Hore01
Copy link
Copy Markdown
Contributor

@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.

Copy link
Copy Markdown
Contributor

@skrawcz skrawcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIce thanks!

@skrawcz
Copy link
Copy Markdown
Contributor

skrawcz commented May 9, 2026

@Hore01 looks great. Mind fixing the pre-commit check?

ruff format..............................................................Failed
- hook id: ruff-format
- files were modified by this hook

  1 file reformatted, 1010 files left unchanged
  warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `ui/sdk/ruff.toml`:
    - 'per-file-ignores' -> 'lint.per-file-ignores'

So just need to run ruff

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>
@skrawcz skrawcz force-pushed the docs/issue-1044-testing-guide branch from ccceb70 to dca946c Compare May 11, 2026 04:44
@skrawcz skrawcz merged commit b41a1de into apache:main May 11, 2026
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

2 participants