From f3cfc2244991de99d74c78d387dffacd9e93d788 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Wynen Date: Tue, 17 Mar 2026 13:19:07 +0100 Subject: [PATCH] Add hook to check test file names --- .pre-commit-config.yaml | 7 +++++++ tools/check-test-file-name.py | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tools/check-test-file-name.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ebffcb5c..bf65b69f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,13 @@ repos: - id: trailing-whitespace args: [ --markdown-linebreak-ext=md ] exclude: '\.svg' + - repo: local + hooks: + - id: check-test-file-name + name: check test file name convention + entry: python tools/check-test-file-name.py + language: python + files: '(tests/.*\.py)$' - repo: https://github.com/kynan/nbstripout rev: 0.7.1 hooks: diff --git a/tools/check-test-file-name.py b/tools/check-test-file-name.py new file mode 100644 index 00000000..b5dce929 --- /dev/null +++ b/tools/check-test-file-name.py @@ -0,0 +1,21 @@ +from pathlib import Path +import sys + +ALLOWED_NAMES = ("conftest.py",) + + +def main(): + errors = False + paths = map(Path, sys.argv[1:]) + for path in paths: + if path.name in ALLOWED_NAMES: + continue + if not path.stem.endswith("_test"): + sys.stderr.write(f"Bad test file name: {path}\n") + errors = True + + sys.exit(int(errors)) + + +if __name__ == "__main__": + main()