HN Reader

NewTopBestAskShowJob
Show HN: Jinjatest – type-safe tests and branch coverage for Jinja templates
score icon1
comment icon0
12 hours agoby demoonkevin
Hi HN — I’m Kevin. As many of you, I've been using Jinja templates to render LLM prompts, where subtle bugs can introduce unexpected LLM behavior that is hard to debug. And writing unit tests to prevent those bugs is painful: you end up doing assertions against raw strings, which is brittle and forces you to keep track of format changes, etc.

So I built jinjatest: a Python library + pytest plugin that lets you test Jinja templates with structure, and (the part I haven’t seen elsewhere) get branch coverage reports for templates.

What it does:

- Template branch coverage via runtime instrumentation: pytest --jt-cov, fail-under thresholds, and term/html/json/xml reports

- Type-safe render context validation with Pydantic + StrictUndefined by default (missing vars fail loudly)

- Parse rendered output as JSON/YAML/XML/markdown "(including fenced code blocks) so tests can assert on structured data

- Optional anchors/traces inside templates for section-level assertions / verifying branches were taken

Open to feedback!

No comments