Skip to content

Other reporters

Report management for ANTA.

ReportJinja

ReportJinja(template_path: pathlib.Path)

Report builder based on a Jinja2 template.

Source code in anta/reporter/__init__.py
233
234
235
236
237
238
239
def __init__(self, template_path: pathlib.Path) -> None:
    """Create a ReportJinja instance."""
    if not template_path.is_file():
        msg = f"template file is not found: {template_path}"
        raise FileNotFoundError(msg)

    self.template_path = template_path

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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
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})

ReportTable

TableReport Generate a Table based on TestResult.

Headers dataclass

Headers(
    device: str = "Device",
    test_case: str = "Test Name",
    number_of_success: str = "# of success",
    number_of_failure: str = "# of failure",
    number_of_skipped: str = "# of skipped",
    number_of_errors: str = "# of errors",
    list_of_error_nodes: str = "List of failed or error nodes",
    list_of_error_tests: str = "List of failed or error test cases",
)

Headers for the table report.

report_all

report_all(
    manager: ResultManager, title: str = "All tests results"
) -> Table

Create a table report with all tests for one or all devices.

Create table with full output: Device | Test Name | Test Status | Message(s) | Test description | Test category

Parameters:

Name Type Description Default
manager ResultManager

A ResultManager instance.

required
title str

Title for the report. Defaults to ‘All tests results’.

'All tests results'

Returns:

Type Description
Table

A fully populated rich Table.

Source code in anta/reporter/__init__.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def report_all(self, manager: ResultManager, title: str = "All tests results") -> Table:
    """Create a table report with all tests for one or all devices.

    Create table with full output: Device | Test Name | Test Status | Message(s) | Test description | Test category

    Parameters
    ----------
    manager
        A ResultManager instance.
    title
        Title for the report. Defaults to 'All tests results'.

    Returns
    -------
    Table
        A fully populated rich `Table`.
    """
    table = Table(title=title, show_lines=True)
    headers = ["Device", "Test Name", "Test Status", "Message(s)", "Test description", "Test category"]
    table = self._build_headers(headers=headers, table=table)

    def add_line(result: TestResult) -> None:
        state = self._color_result(result.result)
        message = self._split_list_to_txt_list(result.messages) if len(result.messages) > 0 else ""
        categories = ", ".join(convert_categories(result.categories))
        table.add_row(str(result.name), result.test, state, message, result.description, categories)

    for result in manager.results:
        add_line(result)
    return table

report_summary_devices

report_summary_devices(
    manager: ResultManager,
    devices: list[str] | None = None,
    title: str = "Summary per device",
) -> Table

Create a table report with result aggregated per device.

Create table with full output: Device | # of success | # of skipped | # of failure | # of errors | List of failed or error test cases

Parameters:

Name Type Description Default
manager ResultManager

A ResultManager instance.

required
devices list[str] | None

List of device names to include. None to select all devices.

None
title str

Title of the report.

'Summary per device'

Returns:

Type Description
Table

A fully populated rich Table.

Source code in anta/reporter/__init__.py
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
def report_summary_devices(
    self,
    manager: ResultManager,
    devices: list[str] | None = None,
    title: str = "Summary per device",
) -> Table:
    """Create a table report with result aggregated per device.

    Create table with full output: Device | # of success | # of skipped | # of failure | # of errors | List of failed or error test cases

    Parameters
    ----------
    manager
        A ResultManager instance.
    devices
        List of device names to include. None to select all devices.
    title
        Title of the report.

    Returns
    -------
    Table
        A fully populated rich `Table`.
    """
    table = Table(title=title, show_lines=True)
    headers = [
        self.Headers.device,
        self.Headers.number_of_success,
        self.Headers.number_of_skipped,
        self.Headers.number_of_failure,
        self.Headers.number_of_errors,
        self.Headers.list_of_error_tests,
    ]
    table = self._build_headers(headers=headers, table=table)
    for device, stats in sorted(manager.device_stats.items()):
        if devices is None or device in devices:
            table.add_row(
                device,
                str(stats.tests_success_count),
                str(stats.tests_skipped_count),
                str(stats.tests_failure_count),
                str(stats.tests_error_count),
                ", ".join(stats.tests_failure),
            )
    return table

report_summary_tests

report_summary_tests(
    manager: ResultManager,
    tests: list[str] | None = None,
    title: str = "Summary per test",
) -> Table

Create a table report with result aggregated per test.

Create table with full output: Test Name | # of success | # of skipped | # of failure | # of errors | List of failed or error nodes

Parameters:

Name Type Description Default
manager ResultManager

A ResultManager instance.

required
tests list[str] | None

List of test names to include. None to select all tests.

None
title str

Title of the report.

'Summary per test'

Returns:

Type Description
Table

A fully populated rich Table.

Source code in anta/reporter/__init__.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def report_summary_tests(
    self,
    manager: ResultManager,
    tests: list[str] | None = None,
    title: str = "Summary per test",
) -> Table:
    """Create a table report with result aggregated per test.

    Create table with full output:
    Test Name | # of success | # of skipped | # of failure | # of errors | List of failed or error nodes

    Parameters
    ----------
    manager
        A ResultManager instance.
    tests
        List of test names to include. None to select all tests.
    title
        Title of the report.

    Returns
    -------
    Table
        A fully populated rich `Table`.
    """
    table = Table(title=title, show_lines=True)
    headers = [
        self.Headers.test_case,
        self.Headers.number_of_success,
        self.Headers.number_of_skipped,
        self.Headers.number_of_failure,
        self.Headers.number_of_errors,
        self.Headers.list_of_error_nodes,
    ]
    table = self._build_headers(headers=headers, table=table)
    for test, stats in sorted(manager.test_stats.items()):
        if tests is None or test in tests:
            table.add_row(
                test,
                str(stats.devices_success_count),
                str(stats.devices_skipped_count),
                str(stats.devices_failure_count),
                str(stats.devices_error_count),
                ", ".join(stats.devices_failure),
            )
    return table