{
  "id": "python/pytest-fail-with-traceback-error",
  "signature": "pytest.fail.Exception: pytest.fail() called with message 'Test failed' and no active test",
  "signature_zh": "pytest.fail.Exception：调用 pytest.fail() 时消息为 'Test failed' 且没有活动测试",
  "regex": "pytest\\.fail\\.Exception:\\ pytest\\.fail\\(\\)\\ called\\ with\\ message\\ 'Test\\ failed'\\ and\\ no\\ active\\ test",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "pytest.fail() is called outside of a test function, e.g., in a fixture setup or teardown, where no test context exists.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest.fail() 在测试函数外部调用，例如在夹具设置或拆卸中，此时没有测试上下文。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using pytest.fail in a conftest.py fixture without test context",
      "why_fails": "Fixtures are not tests; pytest.fail is intended for test functions only.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Catching the exception with try-except to continue execution",
      "why_fails": "pytest.fail raises a special exception that propagates; catching it may hide failures.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Move the pytest.fail() call inside a test function rather than in fixture code.",
      "success_rate": 0.95,
      "how": "def test_example(): pytest.fail('Test failed')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use assert statements in fixtures instead of pytest.fail.",
      "success_rate": 0.9,
      "how": "assert condition, 'Fixture condition not met'",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}