pytest_test_categories.reporting

Test size reporting functionality.

This module provides classes and functions for generating reports about test size distribution and execution statistics. It supports both summary and detailed reports, with information about test sizes, execution times, and status.

Example usage:

pytest –test-size-report pytest –test-size-report=detailed pytest –test-size-report path/to/tests/

Classes

BaselineViolation

Record of a performance baseline violation.

TestSizeReport

Generator for test size reports.

Module Contents

class pytest_test_categories.reporting.BaselineViolation(/, **data)[source]

Bases: pydantic.BaseModel

Record of a performance baseline violation.

Tracks when a test exceeds its custom performance baseline, which is stricter than the category’s default time limit.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

actual: float[source]
baseline: float[source]
category_limit: float[source]
nodeid: str[source]
class pytest_test_categories.reporting.TestSizeReport(/, **data)[source]

Bases: pydantic.BaseModel

Generator for test size reports.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

add_baseline_violation(nodeid, baseline, category_limit, actual)[source]

Record a baseline violation for a test.

Parameters:
  • nodeid (str) – The pytest node ID of the test

  • baseline (float) – The custom baseline limit in seconds

  • category_limit (float) – The category’s default time limit in seconds

  • actual (float) – The actual test duration in seconds

Return type:

None

add_test(nodeid, size, duration=None, outcome='passed')[source]

Add a test to the report.

Parameters:
  • nodeid (str) – The pytest node ID of the test

  • size (pytest_test_categories.types.TestSize | None) – The test size category, or None if unsized

  • duration (float | None) – The test execution time in seconds, if available

  • outcome (str) – The test outcome (passed, failed, etc.)

Return type:

None

exceeds_time_limit(nodeid, size)[source]

Check if a test exceeds its time limit based on size.

Parameters:
Return type:

bool

get_size_counts()[source]

Get the count of tests by size category.

Return type:

dict[str, int]

get_size_percentages()[source]

Get the percentage of tests by size category.

Return type:

dict[str, float]

get_total_tests()[source]

Get the total number of tests in the report.

Return type:

int

has_baseline_violation(nodeid)[source]

Check if a test has a baseline violation.

Parameters:

nodeid (str) – The pytest node ID of the test

Returns:

True if the test exceeded its custom baseline.

Return type:

bool

write_basic_report(terminalreporter)[source]

Write a basic summary report to the terminal.

Parameters:

terminalreporter (pytest.TerminalReporter)

Return type:

None

write_detailed_report(terminalreporter)[source]

Write a detailed report to the terminal.

Parameters:

terminalreporter (pytest.TerminalReporter)

Return type:

None

baseline_violations: dict[str, BaselineViolation] = None[source]
sized_tests: collections.defaultdict[pytest_test_categories.types.TestSize, list[str]] = None[source]
test_durations: dict[str, float] = None[source]
test_outcomes: dict[str, str] = None[source]
unsized_tests: list[str] = None[source]