pytest_test_categories.distribution.config

Distribution configuration for configurable target percentages.

This module provides the DistributionConfig model for configuring custom distribution targets and tolerances for test sizes.

Example

>>> from pytest_test_categories.distribution.config import DistributionConfig
>>> config = DistributionConfig(
...     small_target=70.0,
...     medium_target=20.0,
...     large_target=10.0,
... )
>>> config.get_small_range()
DistributionRange(target=70.0, tolerance=5.0)

Attributes

Classes

DistributionConfig

Configuration for distribution targets across all test sizes.

Module Contents

class pytest_test_categories.distribution.config.DistributionConfig(/, **data)[source]

Bases: pydantic.BaseModel

Configuration for distribution targets across all test sizes.

This model holds configurable distribution targets and tolerances for each test size category. Users can override the defaults via pyproject.toml, pytest.ini, or CLI options.

Default values match Google’s Software Engineering at Google recommendations: - Small: 80% target (+/-5% tolerance) - Medium: 15% target (+/-5% tolerance) - Large/XLarge: 5% target (+/-3% tolerance)

Example

>>> config = DistributionConfig(small_target=70.0, medium_target=20.0, large_target=10.0)
>>> config.get_small_range()
DistributionRange(target=70.0, tolerance=5.0)

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)

get_large_xlarge_range()[source]

Get the DistributionRange for large/xlarge tests combined.

Returns:

DistributionRange configured for large/xlarge tests.

Return type:

pytest_test_categories.distribution.stats.DistributionRange

get_medium_range()[source]

Get the DistributionRange for medium tests.

Returns:

DistributionRange configured for medium tests.

Return type:

pytest_test_categories.distribution.stats.DistributionRange

get_small_range()[source]

Get the DistributionRange for small tests.

Returns:

DistributionRange configured for small tests.

Return type:

pytest_test_categories.distribution.stats.DistributionRange

large_target: Annotated[float, Field(ge=0.0, le=ONE_HUNDRED_PERCENT, description='Target percentage for large/xlarge tests')] = 5.0[source]
large_tolerance: Annotated[float, Field(gt=0.0, le=20.0, description='Tolerance percentage for large/xlarge tests')] = 3.0[source]
medium_target: Annotated[float, Field(ge=0.0, le=ONE_HUNDRED_PERCENT, description='Target percentage for medium tests')] = 15.0[source]
medium_tolerance: Annotated[float, Field(gt=0.0, le=20.0, description='Tolerance percentage for medium tests')] = 5.0[source]
model_config[source]

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

small_target: Annotated[float, Field(ge=0.0, le=ONE_HUNDRED_PERCENT, description='Target percentage for small tests')] = 80.0[source]
small_tolerance: Annotated[float, Field(gt=0.0, le=20.0, description='Tolerance percentage for small tests')] = 5.0[source]
property targets_sum: float[source]

Calculate the sum of all target percentages.

Returns:

The sum of small_target, medium_target, and large_target.

Return type:

float

property targets_sum_to_100: bool[source]

Check if targets sum to 100% within rounding tolerance.

Returns:

True if targets sum to approximately 100%, False otherwise.

Return type:

bool

pytest_test_categories.distribution.config.DEFAULT_DISTRIBUTION_CONFIG[source]