{
  "id": "python/pytest-freezegun-datetime-import",
  "signature": "AssertionError: assert datetime.datetime(2024, 1, 1, 0, 0) == datetime.datetime(2025, 6, 1, 12, 0)\n# freezegun is active but the imported datetime is the real one",
  "signature_zh": "AssertionError: assert datetime.datetime(2024, 1, 1, 0, 0) == datetime.datetime(2025, 6, 1, 12, 0)\n# freezegun 已激活，但导入的 datetime 是真实的那一个",
  "regex": "AssertionError:\\ assert\\ datetime\\.datetime\\(2024,\\ 1,\\ 1,\\ 0,\\ 0\\)\\ ==\\ datetime\\.datetime\\(2025,\\ 6,\\ 1,\\ 12,\\ 0\\)\\\n\\#\\ freezegun\\ is\\ active\\ but\\ the\\ imported\\ datetime\\ is\\ the\\ real\\ one",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The code under test imported datetime as 'from datetime import datetime' before freezegun patched the module, so the test holds a reference to the unpatched class.",
  "root_cause_type": "generic",
  "root_cause_zh": "被测代码在 freezegun patch 模块之前以 'from datetime import datetime' 方式导入了 datetime，导致测试持有未打补丁的类引用。",
  "versions": [
    {
      "version": "1.5.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "tick only affects the patched clock; the unpatched datetime reference is unaffected and still returns real time.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Timezone is not the issue; the datetime class itself is not the one freezegun patched.",
      "fail_rate": 0.92,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.94,
      "how": "# BAD:  from datetime import datetime\n# GOOD: import datetime\nthen use datetime.datetime.now()\n\n# Test:\nfrom freezegun import freeze_time\n\n@freeze_time('2025-06-01 12:00:00')\ndef test_x():\n    assert get_now() == datetime.datetime(2025, 6, 1, 12, 0)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "import importlib\n\n@freeze_time('2025-06-01')\ndef test_x():\n    import myapp.clock\n    importlib.reload(myapp.clock)\n    assert myapp.clock.now().year == 2025",
      "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": "2025-02-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}