@@ -2,7 +2,7 @@ name: "Test File Naming Check"
22
33on :
44 pull_request :
5- types : [opened, reopened, synchronize, edited ]
5+ types : [opened, reopened, edited, synchronize ]
66
77permissions :
88 contents : read
@@ -12,51 +12,41 @@ concurrency:
1212 cancel-in-progress : true
1313
1414jobs :
15- test-name-check :
16- name : Test File Naming Check
15+ test-file-naming :
16+ name : Test File Naming Check (pull request)
1717 runs-on : ubuntu-latest
1818
1919 steps :
20- - name : Harden the runner (Audit all outbound calls)
21- uses : step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
20+ - name : Harden the runner
21+ uses : step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a
2222 with :
2323 egress-policy : audit
2424
25- # Using the specific commit SHA for actions/checkout@v5.0.0, as requested
2625 - name : Checkout repository
27- uses : actions/checkout@8ade135a368bb9860e15bcafd2cf940ba6f36c4c
26+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
2827
29- - name : Validate test file naming convention
28+ - name : Validate test filename convention
29+ shell : bash
3030 run : |
31- echo "🔍 Checking test file naming rules..."
32-
33- # Helper files that must be excluded from naming validation
34- EXCLUDES="__init__.py conftest.py mock_server.py utils_for_test.py"
35-
36- # Build exclude arguments for find
37- EX_ARGS=""
38- for f in $EXCLUDES; do
39- EX_ARGS="$EX_ARGS ! -name \"$f\""
40- done
41-
42- # Rule 1 — Unit tests (tests/unit) must start with test_*.py
43- echo "➡️ Checking UNIT tests (must start with test_)..."
44- invalid_unit=$(eval "find tests/unit -type f -name '*.py' $EX_ARGS ! -name 'test_*.py'")
45-
46- # Rule 2 — Integration tests (tests/integration) must end with *_test.py
47- echo "➡️ Checking INTEGRATION tests (must end with _test.py)..."
48- invalid_integration=$(eval "find tests/integration -type f -name '*.py' $EX_ARGS ! -name '*_test.py'")
49-
50- if [ -n "$invalid_unit" ]; then
51- echo "❌ Invalid Unit Test Filenames:"
52- echo "$invalid_unit"
31+ echo "🔍 Checking for invalid test filenames..."
32+
33+ invalid_files=$(
34+ find tests -type f -name "*.py" \
35+ ! -name "*_test.py" \
36+ ! -path "tests/__init__.py" \
37+ ! -path "tests/unit/__init__.py" \
38+ ! -path "tests/unit/conftest.py" \
39+ ! -path "tests/unit/mock_server.py" \
40+ ! -path "tests/integration/__init__.py" \
41+ ! -path "tests/integration/utils_for_test.py" \
42+ | sort || true
43+ )
44+
45+ if [ -n "$invalid_files" ]; then
46+ echo "❌ Invalid filenames detected (must end with _test.py):"
47+ echo "$invalid_files"
48+ echo
5349 exit 1
5450 fi
5551
56- if [ -n "$invalid_integration" ]; then
57- echo "❌ Invalid Integration Test Filenames:"
58- echo "$invalid_integration"
59- exit 1
60- fi
61-
62- echo "✅ All test files follow the correct conventions!"
52+ echo "✅ All test filenames follow the convention (*_test.py)."
0 commit comments