Add CI step for checking redundant test patches (#7126)

This commit is contained in:
Shahar Naveh authored and GitHub committed 2026-02-15 20:39:57 +09:00
1 parent 2567355a99
commit 64088bb624
2 files changed
+60 -1

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env python
import ast
import pathlib
import sys
ROOT = pathlib.Path(__file__).parents[1]
TEST_DIR = ROOT / "Lib" / "test"
def main():
exit_status = 0
for file in TEST_DIR.rglob("**/*.py"):
try:
contents = file.read_text(encoding="utf-8")
except UnicodeDecodeError:
continue
try:
tree = ast.parse(contents)
except SyntaxError:
continue
for node in ast.walk(tree):
if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
continue
name = node.name
if not name.startswith("test"):
continue
if node.decorator_list:
continue
func_code = ast.unparse(node.body)
if func_code in (
f"await super().{name}()",
f"return await super().{name}()",
f"return super().{name}()",
f"super().{name}()",
):
exit_status += 1
rel = file.relative_to(ROOT)
lineno = node.lineno
print(
f"{rel}:{name}:{lineno} is a test patch that can be safely removed",
file=sys.stderr,
)
return exit_status
if __name__ == "__main__":
exit(main())