示例工程 22-object-model-refcount-gc
22-object-model-refcount-gc/05-tracemalloc-growth/test_tracemalloc_growth.py
"""test_tracemalloc_growth.py"""
from __future__ import annotations
import pytest
from tracemalloc_growth import main, measure
def test_growth_is_visible() -> None:
count, current, peak = measure(10_000)
assert count == 10_000
assert current > 100 * 1024
assert peak >= current
def test_smaller_list_uses_less() -> None:
_, small, _ = measure(100)
_, large, _ = measure(10_000)
assert small < large
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
main()
out = capsys.readouterr().out
assert "current_kib:" in out
assert "peak_gte_current: True" in out