{
  "id": "python/pytest-collection-warning-coroutine",
  "signature": "PytestCollectionWarning: cannot collect test class 'TestSession' because it has a __init__ constructor",
  "signature_zh": "PytestCollectionWarning: 无法收集测试类 'TestSession'，因为它有 __init__ 构造函数",
  "regex": "PytestCollectionWarning:\\ cannot\\ collect\\ test\\ class\\ 'TestSession'\\ because\\ it\\ has\\ a\\ __init__\\ constructor",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "pytest collects any class named Test* but refuses classes with __init__. A domain class named TestSession (e.g., a SQLAlchemy model) collides with pytest's naming convention.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest 会收集任何以 Test* 命名的类，但拒绝有 __init__ 的类。名为 TestSession 的领域类（如 SQLAlchemy 模型）与 pytest 命名约定冲突。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "pytest checks the class attribute before instantiation; instance attributes are never seen.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The model is imported transitively by many tests; the warning persists.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.96,
      "how": "Set __test__ = False on the class:\n\nclass TestSession(Base):\n    __test__ = False\n    __tablename__ = 'sessions'",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Or rename the class to avoid the Test prefix (e.g., SessionRecord).",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}