Skip to content

Jinja Reporter

ReportJinja

ReportJinja(template_path: Path)

Report builder based on a Jinja2 template.

render

render(
    data: list[dict[str, Any]],
    *,
    trim_blocks: bool = True,
    lstrip_blocks: bool = True
) -> str

Build a report based on a Jinja2 template.

Report is built based on a J2 template provided by user. Data structure sent to template is:

Example
>>> print(ResultManager.json)
[
    {
        name: ...,
        test: ...,
        result: ...,
        messages: [...]
        categories: ...,
        description: ...,
    }
]

Parameters:

Name Type Description Default
data list[dict[str, Any]]

List of results from ResultManager.results.

required
trim_blocks bool

enable trim_blocks for J2 rendering.

True
lstrip_blocks bool

enable lstrip_blocks for J2 rendering.

True

Returns:

Type Description
str

Rendered template

Source code in anta/reporter/__init__.py
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
def render(self, data: list[dict[str, Any]], *, trim_blocks: bool = True, lstrip_blocks: bool = True) -> str:
    """Build a report based on a Jinja2 template.

    Report is built based on a J2 template provided by user.
    Data structure sent to template is:

    Example
    -------
    ```
    >>> print(ResultManager.json)
    [
        {
            name: ...,
            test: ...,
            result: ...,
            messages: [...]
            categories: ...,
            description: ...,
        }
    ]
    ```

    Parameters
    ----------
    data
        List of results from `ResultManager.results`.
    trim_blocks
        enable trim_blocks for J2 rendering.
    lstrip_blocks
        enable lstrip_blocks for J2 rendering.

    Returns
    -------
    str
        Rendered template

    """
    with self.template_path.open(encoding="utf-8") as file_:
        template = Template(file_.read(), trim_blocks=trim_blocks, lstrip_blocks=lstrip_blocks)

    return template.render({"data": data})