Skip to content

Add failing tests for Issue #450: IndexError on empty test_results#463

Open
Serhan-Asad wants to merge 3 commits intopromptdriven:mainfrom
Serhan-Asad:fix/issue-450
Open

Add failing tests for Issue #450: IndexError on empty test_results#463
Serhan-Asad wants to merge 3 commits intopromptdriven:mainfrom
Serhan-Asad:fix/issue-450

Conversation

@Serhan-Asad
Copy link
Contributor

Summary

Adds failing tests that detect the bug reported in #450 where PDD crashes with IndexError: list index out of range when pytest fails to collect or execute tests.

Test Files

  • Unit tests: tests/test_fix_error_loop.py (6 new test cases)
  • E2E tests: tests/test_e2e_issue_450_pytest_collection_failure.py (10 new test cases)

What This PR Contains

  • ✅ Failing unit tests that reproduce the reported bug
  • ✅ Failing E2E tests that verify the bug at integration level
  • ✅ Tests are verified to fail on current code and will pass once the bug is fixed
  • ✅ Comprehensive coverage of 16+ real-world failure scenarios

Root Cause

Location: pdd/fix_error_loop.py:213

The bug is a logic error in the defensive programming pattern:

results = output_data.get("test_results", [{}])[0]

The default value [{}] only applies when the key is MISSING, not when it exists with an EMPTY list. When pytest collection/execution fails and returns {"test_results": []}, accessing [0] on the empty list causes IndexError.

Test Coverage

Unit Tests (6 cases)

  1. Empty test_results list - Primary bug (IndexError)
  2. Missing test_results key - Verifies default value works
  3. test_results is None - Type validation (TypeError)
  4. test_results is string - Type validation (AttributeError)
  5. Invalid dict in list - Malformed structure (AttributeError)
  6. Integration test - Collection failure simulation

E2E Tests (10 cases)

  1. Primary bug: Empty test_results list
  2. Import error scenario
  3. Syntax error scenario
  4. No tests found scenario
  5. Missing fixture scenario
  6. Permission denied scenario
  7. Complete user workflow from Issue IndexError crash when pytest collection/execution fails (empty test_results) #450
  8. Edge case: test_results is None
  9. Edge case: test_results is string
  10. Edge case: test_results contains None

Next Steps

  1. Implement the fix at pdd/fix_error_loop.py:213
  2. Add validation to check if test_results list is non-empty before accessing [0]
  3. Add type validation to ensure test_results is a list
  4. Provide helpful error messages for common failure patterns
  5. Verify all unit tests pass
  6. Verify all E2E tests pass
  7. Run full test suite to check for regressions
  8. Mark PR as ready for review

Recommended Fix Approach

The issue proposes a robust solution with:

  • Two-stage validation (type check + empty check)
  • Helpful error messages for common patterns (ImportError, SyntaxError, etc.)
  • Proper logging for debugging
  • Graceful handling of all 16+ failure scenarios

Fixes #450


Generated by PDD agentic bug workflow (Steps 1-10 complete)

…t_results

This commit adds comprehensive unit and E2E tests that detect the bug
reported in Issue promptdriven#450 where PDD crashes with IndexError when pytest
fails to collect or execute tests.

Root Cause: Line 213 in pdd/fix_error_loop.py uses
output_data.get("test_results", [{}])[0] which assumes the default
value protects against empty lists. However, Python's .get() only
returns the default when the key is MISSING, not when it exists
with an EMPTY list.

Tests Added:
- 6 unit tests in tests/test_fix_error_loop.py
  - Empty test_results list (primary bug)
  - Missing test_results key
  - Type validation for None, string, invalid dict
  - Integration test for collection failures

- 10 E2E tests in tests/test_e2e_issue_450_pytest_collection_failure.py
  - Complete user workflow scenarios
  - Real-world pytest failure cases (ImportError, SyntaxError, etc.)
  - Edge cases with malformed data

All tests currently FAIL on the buggy code (confirming they detect
the bug). They will PASS once the fix is implemented.

Related: promptdriven#450

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@Serhan-Asad Serhan-Asad marked this pull request as ready for review February 5, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError crash when pytest collection/execution fails (empty test_results)

1 participant