{
  "id": "python/pytest-assertion-introspection-error",
  "signature": "E   pytest.PytestAssertRewriteWarning: Module already imported so cannot be rewritten",
  "signature_zh": "E   pytest.PytestAssertRewriteWarning: 模块已被导入，无法重写",
  "regex": "E\\ \\ \\ pytest\\.PytestAssertRewriteWarning:\\ Module\\ already\\ imported\\ so\\ cannot\\ be\\ rewritten",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "A plugin or conftest imports a module before pytest's assertion rewriter can register it, so assert statements in that module are not rewritten and produce poor failure messages.",
  "root_cause_type": "generic",
  "root_cause_zh": "插件或 conftest 在 pytest 断言重写器注册之前导入了模块，导致该模块中的 assert 语句未被重写，产生较差的失败信息。",
  "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": "The warning is suppressed but assertion rewriting remains disabled for that module.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Import order still places it after pytest's plugin loading in many cases, so the warning persists.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Register the module for rewriting before any import:\n\n# conftest.py (top)\nimport pytest\npytest.register_assert_rewrite('myapp.core')\n\nimport myapp.core  # after registration",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Avoid importing application modules at conftest top level; import inside fixtures instead.",
      "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-12-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}