{
  "id": "python/pytest-parametrize-index-error",
  "signature": "IndexError: list index out of range in parametrized test with indirect=True",
  "signature_zh": "索引错误：在带有 indirect=True 的参数化测试中列表索引超出范围",
  "regex": "IndexError:\\ list\\ index\\ out\\ of\\ range\\ in\\ parametrized\\ test\\ with\\ indirect=True",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "When using pytest.mark.parametrize with indirect=True, the number of fixture values provided does not match the number of test arguments, causing an index error when accessing the parameter list.",
  "root_cause_type": "generic",
  "root_cause_zh": "当使用pytest.mark.parametrize并设置indirect=True时，提供的fixture值数量与测试参数数量不匹配，导致访问参数列表时出现索引错误。",
  "versions": [
    {
      "version": "7.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Removing indirect=True from the parametrize decorator",
      "why_fails": "This changes how fixtures are injected, potentially breaking the test logic that depends on indirect fixture configuration.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding extra dummy values to the parameter list without adjusting fixture definitions",
      "why_fails": "This may cause fixture resolution failures or incorrect test behavior if the extra values are not handled.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the number of values in the parametrize list matches the number of fixture arguments",
      "success_rate": 0.95,
      "how": "If you have two fixtures (fixture1, fixture2) with indirect=True, provide a list of tuples: \n@pytest.mark.parametrize('fixture1,fixture2', [(val1, val2), (val3, val4)], indirect=True)\ndef test_example(fixture1, fixture2):\n    ...\nEach tuple must have exactly two elements.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use indirect for only specific fixtures by specifying them explicitly",
      "success_rate": 0.85,
      "how": "@pytest.mark.parametrize('fixture1', [val1, val2], indirect=['fixture1'])\ndef test_example(fixture1, other_arg):\n    ...\nThis avoids index errors for mixed indirect and direct parameters.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}