-
Notifications
You must be signed in to change notification settings - Fork 614
[BUG]: pre-commit name-tests-test hook fails on test utility files #2735
Description
🐞 Bug Summary
The name-tests-test pre-commit hook fails when running make pre-commit because it incorrectly flags test utility files (load test scripts, benchmark scripts, and render utilities) that don't follow the test_*.py naming convention. These files are legitimate test infrastructure files that should be excluded from the naming check.
🧩 Affected Component
Select the area of the project impacted:
-
mcpgateway- API -
mcpgateway- UI (admin panel) -
mcpgateway.wrapper- stdio wrapper - Federation or Transports
- CLI, Makefiles, or shell scripts
- Container setup (Docker/Podman/Compose)
- Other (explain below)
Additional context: Pre-commit configuration (.pre-commit-lite.yaml)
🔁 Steps to Reproduce
- Run
make pre-commitin the project root - Observe the
name-tests-testhook failure - Review the error output showing 8 files that don't match the
test_.*\.pypattern
🤔 Expected Behavior
The name-tests-test hook should exclude test utility files that are not actual test cases:
- Load testing scripts (
tests/loadtest/locustfile*.py) - Benchmark scripts (
tests/client/benchmark_*.py) - Render utilities (
tests/jmeter/render_fragments.py)
These files serve as test infrastructure and should not be required to follow the test_*.py naming convention.
📓 Logs / Error Output
🐍 Python Tests Naming...................................................Failed
- hook id: name-tests-test
- exit code: 1
tests/loadtest/locustfile_baseline.py does not match pattern "test_.*\.py"
tests/loadtest/locustfile_highthroughput.py does not match pattern "test_.*\.py"
tests/loadtest/locustfile.py does not match pattern "test_.*\.py"
tests/loadtest/locustfile_spin_detector.py does not match pattern "test_.*\.py"
tests/loadtest/locustfile_agentgateway_mcp_server_time.py does not match pattern "test_.*\.py"
tests/client/benchmark_sweep.py does not match pattern "test_.*\.py"
tests/client/benchmark_httpx.py does not match pattern "test_.*\.py"
tests/jmeter/render_fragments.py does not match pattern "test_.*\.py"
🧠 Environment Info
You can retrieve most of this from the /version endpoint.
| Key | Value |
|---|---|
| Version or commit | main (current) |
| Runtime | Python 3.11+ |
| Platform / OS | macOS / Linux |
| Container | N/A |
🧩 Additional Context (optional)
Current configuration (.pre-commit-lite.yaml lines 366-372):
- id: name-tests-test
name: 🐍 Python Tests Naming
description: Verifies test files in tests/ directories start with `test_`.
language: python
files: (^|/)tests/.+\.py$
exclude: ^tests/(.*/)?(pages|helpers|fuzzers|scripts|fixtures|migration|utils|manual|async|load)/.*\.py$
args: [--pytest-test-first] # `test_.*\.py`Issue: The exclude pattern already excludes load/ but the actual directory is loadtest/. Additionally, client/ and jmeter/ directories containing utility scripts are not excluded.
Proposed fix: Update the exclude pattern to:
exclude: ^tests/(.*/)?(pages|helpers|fuzzers|scripts|fixtures|migration|utils|manual|async|load|loadtest|client|jmeter)/.*\.py$This would exclude:
tests/loadtest/- Locust load testing scriptstests/client/- Benchmark and client testing utilitiestests/jmeter/- JMeter-related render utilities
Note: The same fix should be applied to both .pre-commit-config.yaml (line 366) and .pre-commit-lite.yaml (line 371) to maintain consistency.