From fa4af280492b149653a8b3df4eedeba6e6452cc9 Mon Sep 17 00:00:00 2001 From: Alex Verkhovsky Date: Thu, 20 Aug 2026 22:10:02 -0700 Subject: [PATCH] perf(test): parallel, quiet, cache-free Python test runs Run the suite with pytest-xdist (-n auto): 17.7s to 5.9s wall measured locally. Quiet output when green (-q), short tracebacks and a summary of non-passing outcomes when not (-ra --tb=short). Write nothing to disk: -p no:cacheprovider stops .pytest_cache and PYTHONDONTWRITEBYTECODE=1 stops __pycache__; a warm single-directory bytecode cache measured no faster than cold, so the cache bought nothing. Parallelism exposed a race in test_recon_kit.py: two test classes shared the fixture path tests/_report.md and deleted it after use, so xdist workers could unlink it under each other. All four file-fixture tests there now write into per-test temporary directories. --- package.json | 2 +- .../scripts/tests/test_recon_kit.py | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index b53a79bff..4c4cd78ac 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "quality": "npm run format:check && npm run lint && npm run lint:md && npm run docs:build && npm test && npm run validate:refs && npm run validate:skills && npm run docs:validate-sidebar", "test": "npm run test:docs && npm run test:python", "test:docs": "node docs-site/test/test-site-url.mjs && node docs-site/test/test-rehype-plugins.mjs", - "test:python": "uv run --python 3.11 --with pytest --with \"pyyaml>=6.0.2,<7\" --with \"ruamel.yaml>=0.18\" pytest tools/tests skills", + "test:python": "PYTHONDONTWRITEBYTECODE=1 uv run --python 3.11 --with pytest --with pytest-xdist --with \"pyyaml>=6.0.2,<7\" --with \"ruamel.yaml>=0.18\" pytest -q -ra --tb=short -n auto -p no:cacheprovider tools/tests skills", "validate:refs": "uv run --python 3.11 tools/validate_file_refs.py --strict", "validate:skills": "uv run --python 3.11 tools/validate_skills.py --strict" }, diff --git a/skills/bmad-deep-recon/scripts/tests/test_recon_kit.py b/skills/bmad-deep-recon/scripts/tests/test_recon_kit.py index 217f534ae..e120a7d94 100644 --- a/skills/bmad-deep-recon/scripts/tests/test_recon_kit.py +++ b/skills/bmad-deep-recon/scripts/tests/test_recon_kit.py @@ -7,6 +7,7 @@ import io import json import sys +import tempfile import unittest from contextlib import redirect_stdout from datetime import date @@ -62,12 +63,10 @@ def run(argv): class CitationsTest(unittest.TestCase): def test_cross_check(self): - report = Path(__file__).parent / "_report.md" - report.write_text(REPORT, encoding="utf-8") - try: + with tempfile.TemporaryDirectory() as tmp: + report = Path(tmp) / "report.md" + report.write_text(REPORT, encoding="utf-8") code, result = run(["citations", str(report)]) - finally: - report.unlink() self.assertEqual(result["dangling_markers"], [4]) self.assertEqual(result["orphaned_rows"], [3]) self.assertNotIn(9, result["markers"]) # fenced content ignored @@ -76,12 +75,10 @@ class CitationsTest(unittest.TestCase): class TallyTest(unittest.TestCase): def test_last_status_wins_per_ref(self): - log = Path(__file__).parent / "_memlog.md" - log.write_text(MEMLOG, encoding="utf-8") - try: + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / "memlog.md" + log.write_text(MEMLOG, encoding="utf-8") code, result = run(["tally", str(log)]) - finally: - log.unlink() self.assertEqual(result["by_type"]["claim"], 4) self.assertEqual(result["claims"], {"unverified": 1, "verified": 2}) self.assertEqual(result["claims_total"], 3) # ref=[2] counted once @@ -99,16 +96,14 @@ class StalenessTest(unittest.TestCase): {"claim": "pricing", "class": "pricing", "pub_date": "2026-06"}, {"claim": "odd", "class": "unmapped", "pub_date": "2026-06"}, ]) - f = Path(__file__).parent / "_claims.json" - f.write_text(claims, encoding="utf-8") - try: + with tempfile.TemporaryDirectory() as tmp: + f = Path(tmp) / "claims.json" + f.write_text(claims, encoding="utf-8") code, result = run([ "staleness", str(f), "--windows", '{"size/growth": 18, "pricing": 3}', "--today", "2026-07-22", ]) - finally: - f.unlink() self.assertEqual(result["stale_count"], 1) # sizing recheck 2025-12 < today self.assertEqual(result["earliest_recheck"], "2025-12-01") self.assertEqual(result["no_window_classes"], ["unmapped"]) @@ -126,12 +121,10 @@ class SlugTest(unittest.TestCase): class EscapeSourcesTest(unittest.TestCase): def test_escaping_and_url_validation(self): - report = Path(__file__).parent / "_report.md" - report.write_text(REPORT, encoding="utf-8") - try: + with tempfile.TemporaryDirectory() as tmp: + report = Path(tmp) / "report.md" + report.write_text(REPORT, encoding="utf-8") code, result = run(["escape-sources", str(report)]) - finally: - report.unlink() self.assertEqual(result["rows"], 3) self.assertTrue(any(u.startswith("javascript:") for u in result["invalid_urls"])) self.assertNotIn("javascript:", result["html"]) # never linked