Skip to content

[BUG]: pre-commit name-tests-test hook fails on test utility files #2735

@brian-hussey

Description

@brian-hussey

🐞 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

  1. Run make pre-commit in the project root
  2. Observe the name-tests-test hook failure
  3. Review the error output showing 8 files that don't match the test_.*\.py pattern

🤔 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 scripts
  • tests/client/ - Benchmark and client testing utilities
  • tests/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.

Metadata

Metadata

Assignees

Labels

SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releasebugSomething isn't working

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions