API Reference¶
Decorators¶
pytest_stochastic.stochastic_test(*, expected, atol=0.0, rtol=0.0, failure_prob=1e-08, bounds=None, variance=None, sub_gaussian_param=None, symmetric=False, moment_bound=None, side='two-sided', seed=None)
¶
Decorator that turns a scalar-returning function into a stochastic test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected
|
float
|
Expected value of the test statistic. |
required |
atol
|
float
|
Absolute tolerance. |
0.0
|
rtol
|
float
|
Relative tolerance (fraction of |
0.0
|
failure_prob
|
float
|
Target false-failure probability. |
1e-08
|
bounds
|
tuple[float, float] | None
|
|
None
|
variance
|
float | None
|
Upper bound on |
None
|
sub_gaussian_param
|
float | None
|
Sub-Gaussian parameter sigma. |
None
|
symmetric
|
bool
|
|
False
|
moment_bound
|
tuple[float, float] | None
|
|
None
|
side
|
str
|
|
'two-sided'
|
seed
|
int | None
|
Optional fixed RNG seed for reproducibility. |
None
|
pytest_stochastic.distributional_test(*, reference, test='ks', significance=1e-06, n_samples=10000, seed=None)
¶
Decorator for testing that outputs match a reference distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
object
|
A scipy continuous distribution (e.g. |
required |
test
|
str
|
Statistical test to use: |
'ks'
|
significance
|
float
|
Significance level alpha. The test asserts |
1e-06
|
n_samples
|
int
|
Number of samples to draw from the test function. |
10000
|
seed
|
int | None
|
Optional fixed RNG seed for reproducibility. |
None
|
Types¶
pytest_stochastic.TestConfig
dataclass
¶
Validated configuration for a single stochastic test.
declared_properties
property
¶
Return a dict of all non-None declared distributional properties.
pytest_stochastic.BoundStrategy
dataclass
¶
A concentration inequality strategy.
Each instance encapsulates one bound from the registry: the properties it requires, its sample-size formula, and which estimator it uses.
pytest_stochastic.EstimatorType
¶
Bases: Enum
Estimator used to aggregate samples.
Exceptions¶
pytest_stochastic.ConfigurationError
¶
Bases: Exception
Base error for invalid stochastic test configuration.
pytest_stochastic.NoApplicableBoundError
¶
Bases: ConfigurationError
No concentration bound is applicable with the declared properties.
pytest_stochastic.InvalidToleranceError
¶
Bases: ConfigurationError
The tolerance specification is invalid.
pytest_stochastic.InvalidPropertyError
¶
Bases: ConfigurationError
A declared distributional property is invalid.