---
name: block-test-loops-conditionals
enabled: true
event: file
action: block
conditions:
  - field: file_path
    operator: regex_match
    pattern: tests?/.*\.py$
  - field: new_text
    operator: regex_match
    pattern: def test_[^(]+\([^)]*\)[^:]*:[\s\S]*?\b(for|while|if)\s+[^:]+:[\s\S]*?assert
---

🚫 **Test Quality Violation: Loops or Conditionals in Tests**

Your edit contains a **loop** (`for`/`while`) or **conditional** (`if`) combined with assertions in a test file.

**Why this is blocked:**
- Tests should be deterministic and explicit
- Loops hide which iteration failed
- Conditionals make test behavior unpredictable
- This violates the project's test quality standards (see `tests/quality/`)

**Alternatives:**
1. **Use `@pytest.mark.parametrize`** for multiple test cases:
   ```python
   @pytest.mark.parametrize("input,expected", [
       ("a", 1),
       ("b", 2),
   ])
   def test_example(input, expected):
       assert process(input) == expected
   ```

2. **Create separate test functions** for distinct scenarios

3. **Use fixtures** for setup variations

**Project reference:** See `tests/quality/` for the 23 test smell checks enforced on this codebase.
