"""test_timeout_retry.py""" from __future__ import annotations import asyncio import pytest from timeout_retry import main, retry def test_retries_until_success() -> None: count, result = asyncio.run(retry(fail_times=2, attempts=3)) assert (count, result) == (3, "ok") def test_gives_up_after_attempts() -> None: with pytest.raises(TimeoutError, match="all attempts"): asyncio.run(retry(fail_times=5, attempts=3)) def test_no_failure_single_attempt() -> None: assert asyncio.run(retry(fail_times=0)) == (1, "ok") def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None: asyncio.run(main()) out = capsys.readouterr().out assert "attempts: 3" in out assert "give up: all attempts timed out" in out