pytest_test_categories.distribution.stats

Test distribution statistics.

Attributes

Classes

DistributionRange

Valid range for a test size distribution percentage.

DistributionStats

Test distribution statistics.

TestCounts

Count of tests by size.

TestPercentages

Distribution percentages of tests by size.

Module Contents

class pytest_test_categories.distribution.stats.DistributionRange(/, **data)[source]

Bases: pydantic.BaseModel

Valid range for a test size distribution percentage.

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)

property max_value: float[source]

Maximum acceptable percentage.

Return type:

float

property min_value: float[source]

Minimum acceptable percentage.

Return type:

float

model_config[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

target: float = None[source]
tolerance: float = None[source]
class pytest_test_categories.distribution.stats.DistributionStats(/, **data)[source]

Bases: pydantic.BaseModel

Test distribution statistics.

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)

calculate_percentages()[source]

Calculate the percentage distribution of test sizes.

Return type:

TestPercentages

classmethod update_counts(counts)[source]

Return a new instance with updated counts.

Parameters:

counts (collections.abc.Mapping[pytest_test_categories.types.TestSize, int] | TestCounts)

Return type:

DistributionStats

validate_distribution(config=None)[source]

Validate test distribution against target ranges.

Parameters:

config (pytest_test_categories.distribution.config.DistributionConfig | None) – Optional DistributionConfig with custom targets and tolerances. If not provided, uses DEFAULT_DISTRIBUTION_CONFIG.

Raises:

ValueError – If the distribution is outside the configured target ranges.

Return type:

None

counts: TestCounts = None[source]
model_config[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pytest_test_categories.distribution.stats.TestCounts(/, **data)[source]

Bases: pydantic.BaseModel

Count of tests by size.

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)

large: int = None[source]
medium: int = None[source]
model_config[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

small: int = None[source]
xlarge: int = None[source]
class pytest_test_categories.distribution.stats.TestPercentages(/, **data)[source]

Bases: pydantic.BaseModel

Distribution percentages of tests by size.

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)

classmethod round_to_two_decimals(v)[source]

Round percentage values to two decimal places.

Parameters:

v (float)

Return type:

float

validate_total()[source]

Validate that percentages sum to 100% unless all are 0.

Returns:

The validated TestPercentages instance.

Raises:

ValueError – If percentages don’t sum to 100% (within rounding tolerance).

Return type:

TestPercentages

ROUNDING_TOLERANCE: ClassVar[float] = 0.03[source]
large: float = None[source]
medium: float = None[source]
small: float = None[source]
xlarge: float = None[source]
pytest_test_categories.distribution.stats.DISTRIBUTION_TARGETS[source]
pytest_test_categories.distribution.stats.ONE_HUNDRED_PERCENT: Final[float] = 100.0[source]