API Reference
Low-level API documentation for pytest-repeated internals and extension points.
Using mkdocstrings
This page will be automatically generated from the source code docstrings using mkdocstrings.
Plugin Module
pytest_repeated.plugin
bayes_one_sided_proportion_test(r, n, N, prior_successes=1, prior_failures=1, posterior_threshold_probability=0.95)
Perform a one-sided Bayesian test for a population proportion.
Uses Beta-Binomial conjugate prior to compute posterior probability that the true proportion p > r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
threshold proportion (0 <= r <= 1) |
required |
n
|
int
|
number of successes observed (0 <= n <= N) |
required |
N
|
int
|
total number of trials (N > 0) |
required |
prior_successes
|
float
|
prior pseudo-count for successes (default 1, uninformative) |
1
|
prior_failures
|
float
|
prior pseudo-count for failures (default 1, uninformative) |
1
|
posterior_threshold_probability
|
float
|
credible threshold (default 0.95) |
0.95
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
{ "posterior_prob": float, # P(p > r | data) "passes": bool, # whether posterior_prob >= threshold "alpha": float, # posterior Beta parameter "beta": float, # posterior Beta parameter |
dict
|
} |
Source code in pytest_repeated/plugin.py
one_sided_proportion_test(r, n, N, alpha=0.05)
Perform a one-sided hypothesis test for a population proportion.
Uses exact binomial test for small samples (N < 30 or Nr(1-r) < 10), and normal approximation for larger samples.
H0: p <= r H1: p > r
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
hypothesized proportion under null (0 <= r <= 1) |
required |
n
|
int
|
number of successes observed (0 <= n <= N) |
required |
N
|
int
|
total number of trials (N > 0) |
required |
alpha
|
float
|
significance level for the test (default 0.05) |
0.05
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
{"p_value": float, "reject": bool, "p_hat": float, "method": str} |
Raises:
| Type | Description |
|---|---|
ValueError
|
if input parameters are out of bounds |
Source code in pytest_repeated/plugin.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
pytest_report_teststatus(report, config)
Customize terminal output for repeated tests.
Source code in pytest_repeated/plugin.py
pytest_runtest_logreport(report)
Print detailed run results for -vvv.
Source code in pytest_repeated/plugin.py
Key Functions
pytest_runtest_call
Handles test repetition and error detection. This is the core hook that runs tests multiple times.
pytest_runtest_makereport
Applies statistical evaluation (basic/frequentist/Bayesian) to determine overall test pass/fail.
pytest_runtest_logreport
Displays run-by-run results at verbosity level 3 (-vvv).
Extension Points
pytest-repeated integrates with pytest's hook system. If you're extending or modifying the plugin, these are the key hooks:
pytest_configure: Plugin registration and configurationpytest_runtest_protocol: Test execution protocol overridepytest_runtest_call: Individual test run executionpytest_runtest_makereport: Test result reportingpytest_runtest_logreport: Logging and verbosity handling
Statistical Methods
Wilson Score Interval (Frequentist)
pytest-repeated uses the Wilson score interval for constructing confidence intervals in frequentist testing. This method provides better coverage than the normal approximation, especially for small sample sizes.
Beta-Binomial Model (Bayesian)
The Bayesian approach uses a Beta-Binomial conjugate prior model:
- Prior: Beta(α, β) distribution over success rate θ
- Likelihood: Binomial(n, θ) for observed successes
- Posterior: Beta(α + successes, β + failures)
The test evaluates P(θ ≥ threshold | data) using the posterior CDF.
Next Steps
- Parameters Reference - All decorator parameters
- Basic Usage - Using the plugin
- Development Guide - Contributing to pytest-repeated