mirror of
https://github.com/bmad-code-org/BMAD-METHOD.git
synced 2026-09-01 15:09:07 +08:00
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.
This commit is contained in:
+1
-1
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user