runner
π€ AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
wrknv.memray.runner
¶
Memray stress test runner for pytest integration.
Provides a helper to run a script under memray, collect stats, and assert against baselines β all from a single function call in a test.
Usage in a pytest test::
from wrknv.memray.runner import run_memray_stress
def test_my_allocations(memray_output_dir, memray_baseline, memray_baselines_path):
run_memray_stress(
script="scripts/memray_my_stress.py",
baseline_key="my_total_allocations",
output_dir=memray_output_dir,
baselines=memray_baseline,
baselines_path=memray_baselines_path,
)
Functions¶
run_memray_stress
¶
run_memray_stress(
script: str | Path,
baseline_key: str,
output_dir: Path,
baselines: dict[str, Any],
baselines_path: Path,
output_name: str | None = None,
threshold: float = 0.15,
timeout: int = 300,
) -> int
Run a stress script under memray and check allocations against baseline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
str | Path
|
Path to the stress test script (relative to project root) |
required |
baseline_key
|
str
|
Key in baselines.json for this test |
required |
output_dir
|
Path
|
Directory for memray output files |
required |
baselines
|
dict[str, Any]
|
Current baselines dict |
required |
baselines_path
|
Path
|
Path to baselines.json |
required |
output_name
|
str | None
|
Name for the output .bin file (default: derived from script name) |
None
|
threshold
|
float
|
Allocation regression threshold (default: 15%) |
0.15
|
timeout
|
int
|
Maximum seconds for the stress script (default: 300) |
300
|
Returns:
| Type | Description |
|---|---|
int
|
Total allocation count measured |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If allocations exceed baseline + threshold |