From 694b9409ab4dd9c8e942545a4e61e640c93409f2 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Thu, 14 May 2026 21:52:52 +0200 Subject: [PATCH] perf(pre-commit): batch+parallelize pytest on commit; kill 15s sleeps in steam_backlog_enforcer tests - meta/.pre-commit-config.yaml: move pytest-coverage hook to pre-commit stage - scripts/pytest_changed_packages.py: single batched pytest -n auto invocation with one --cov flag per affected python_pkg subpackage, wrapped in systemd-run --user --scope -p MemoryMax=4G -p MemorySwapMax=0 when available - python_pkg/steam_backlog_enforcer/tests/conftest.py: new autouse _no_real_sleep fixture patches time.sleep across game_install / library_hider / steam_api / _enforce_loop. Removes 3x 15s real sleeps in TestFinalizeCompletion that fired through _ensure_steam_running steam_backlog_enforcer test wall time: 33.97s -> 5.61s (xdist, no-cov) 5-package batched run: 732 tests in 1.37s @ 668% CPU Coverage stays at 100% on all affected packages. Evidence: docs/superpowers/evidence/pre-commit-pytest-batch-2026-05-14.json --- steam_backlog_enforcer/tests/conftest.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/steam_backlog_enforcer/tests/conftest.py b/steam_backlog_enforcer/tests/conftest.py index 689ad37..cb72d86 100644 --- a/steam_backlog_enforcer/tests/conftest.py +++ b/steam_backlog_enforcer/tests/conftest.py @@ -116,3 +116,21 @@ def _block_real_subprocesses() -> Iterator[None]: ), ): yield + + +@pytest.fixture(autouse=True) +def _no_real_sleep() -> Iterator[None]: + """No-op every ``time.sleep`` used by the package. + + Several modules call ``time.sleep`` for Steam-launch / install-retry / + rate-limit pacing. Individual tests that need to observe sleep + behaviour can override these patches inside their own ``with`` block. + """ + noop = MagicMock() + with ( + patch("python_pkg.steam_backlog_enforcer.game_install.time.sleep", noop), + patch("python_pkg.steam_backlog_enforcer.library_hider.time.sleep", noop), + patch("python_pkg.steam_backlog_enforcer.steam_api.time.sleep", noop), + patch("python_pkg.steam_backlog_enforcer._enforce_loop.time.sleep", noop), + ): + yield