import json
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
REPORT = ROOT / "scripts" / "unskip_report.json"
def main():
with open(REPORT) as f:
data = json.load(f)
to_reskip: list[tuple[str, int]] = []
for issue_num, failed_list in data["issues_some_failed"]:
for test_id in failed_list:
to_reskip.append((test_id, issue_num))
edits: dict[
Path, list[tuple[int, int, str]]
] = {} for test_id, issue_num in to_reskip:
parts = test_id.split("::")
module = parts[0] test_name = parts[-1] file_path = ROOT / (module.replace(".", "/") + ".py")
if not file_path.exists():
print("Skip (file not found):", file_path)
continue
content = file_path.read_text()
lines = content.splitlines()
for i, line in enumerate(lines):
if line.strip().startswith("def " + test_name + "("):
indent = len(line) - len(line.lstrip())
decorator = (
" " * indent
+ f'@pytest.mark.skip(reason="Issue #{issue_num}: unskip when fixing")\n'
)
if i > 0 and "pytest.mark.skip" in lines[i - 1]:
continue edits.setdefault(file_path, []).append((i, issue_num, " " * indent))
break
for file_path, items in edits.items():
lines = file_path.read_text().splitlines()
for line_idx, issue_num, indent in sorted(items, key=lambda x: -x[0]):
decorator = (
indent
+ f'@pytest.mark.skip(reason="Issue #{issue_num}: unskip when fixing")'
)
lines.insert(line_idx, decorator)
file_path.write_text("\n".join(lines) + "\n")
print("Re-skipped", len(to_reskip), "tests in", len(edits), "files")
if __name__ == "__main__":
main()