{
  "id": "python/pytest-fail-with-message",
  "signature": "pytest.fail('Test failed due to timeout') -> Failed: Test failed due to timeout",
  "signature_zh": "pytest.fail('测试因超时而失败') -> 失败：测试因超时而失败",
  "regex": "pytest\\.fail\\('Test\\ failed\\ due\\ to\\ timeout'\\)\\ \\->\\ Failed:\\ Test\\ failed\\ due\\ to\\ timeout",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The test explicitly calls pytest.fail() with a custom message, which immediately stops the test and reports a failure, often used for conditional checks that are not covered by standard assertions.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试显式调用pytest.fail()并附带自定义消息，这会立即停止测试并报告失败，通常用于标准断言未涵盖的条件检查。",
  "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": "Replacing pytest.fail() with a simple print statement",
      "why_fails": "This does not stop the test or report failure, so the test may pass even if the condition is met.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using assert False instead of pytest.fail()",
      "why_fails": "This works but provides less descriptive error messages, making debugging harder.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use pytest.fail() with a descriptive message to provide context for the failure",
      "success_rate": 0.95,
      "how": "if condition:\n    pytest.fail('Expected condition to be False, but it was True')\nThis makes the test output clear.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Replace with a custom assertion using pytest.assume for non-fatal failures",
      "success_rate": 0.7,
      "how": "from pytest import assume\nassume(not condition, 'Condition should be False')\nThis allows the test to continue but still report the failure.",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}