@@ -7,12 +7,12 @@ Stop writing brittle substring assertions. Test your templates with structure, v
77## Installation
88
99``` bash
10- pip install jinjatest
10+ uv add jinjatest
1111```
1212
1313With YAML support:
1414``` bash
15- pip install jinjatest[yaml]
15+ uv add jinjatest[yaml]
1616```
1717
1818## Why jinjatest?
@@ -403,6 +403,48 @@ spec = TemplateSpec.from_file("template.j2")
403403spec.assert_variables_subset_of({" user_name" , " plan" , " items" })
404404```
405405
406+ ## Template Coverage
407+
408+ Track branch coverage for your Jinja templates to ensure all conditional paths are tested.
409+
410+ ### Quick Start
411+
412+ ``` bash
413+ pytest --jt-cov
414+ ```
415+
416+ ### CLI Options
417+
418+ | Option | Description |
419+ | --------| -------------|
420+ | ` --jt-cov ` | Enable template coverage |
421+ | ` --jt-cov-fail-under=N ` | Fail if coverage below N% |
422+ | ` --jt-cov-report=TYPE ` | Report type: ` term ` , ` term-missing ` , ` term-verbose ` , ` html ` , ` json ` , ` xml ` |
423+ | ` --jt-cov-html=DIR ` | HTML report directory |
424+ | ` --jt-cov-json=FILE ` | JSON report file |
425+ | ` --jt-cov-xml=FILE ` | JUnit XML report file |
426+ | ` --jt-cov-exclude=PATTERN ` | Glob pattern to exclude templates |
427+
428+ ### Configuration (pyproject.toml)
429+
430+ ``` toml
431+ [tool .jinjatest .coverage ]
432+ enabled = true
433+ fail_under = 80
434+ report = [" term" , " html" ]
435+ html_dir = " jt-htmlcov"
436+ exclude_patterns = [" **/vendor/**" , " *.partial.j2" ]
437+ ```
438+
439+ ### What's Tracked
440+
441+ - ` {% if %} ` / ` {% elif %} ` / ` {% else %} ` branches
442+ - ` {% for %} ` loops (body and else)
443+ - ` {% macro %} ` definitions
444+ - ` {% block %} ` definitions (template inheritance)
445+ - ` {% include %} ` statements
446+ - Ternary expressions (` {{ x if cond else y }} ` )
447+
406448## License
407449
408450MIT
0 commit comments