{
  "id": "python/pytest-freeze-time-not-active",
  "signature": "AssertionError: assert '2026-03-01' == '2024-01-01'\n  # datetime.now() not frozen inside test",
  "signature_zh": "AssertionError: assert '2026-03-01' == '2024-01-01'\n  # 测试内 datetime.now() 未被冻结",
  "regex": "AssertionError:\\ assert\\ '2026\\-03\\-01'\\ ==\\ '2024\\-01\\-01'\\\n\\ \\ \\#\\ datetime\\.now\\(\\)\\ not\\ frozen\\ inside\\ test",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "freezegun's freeze_time decorator patches datetime at import time, but the code under test imported datetime as 'from datetime import datetime', binding the original class before the patch. The patched module-level datetime is not used.",
  "root_cause_type": "generic",
  "root_cause_zh": "freezegun 的 freeze_time 装饰器在导入时补丁 datetime，但被测代码使用 'from datetime import datetime' 导入，在补丁之前就绑定了原始类。被补丁的模块级 datetime 未被使用。",
  "versions": [
    {
      "version": "1.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Time is not the issue; the reference is bound to the unpatched class regardless of duration.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "time-machine also patches the datetime module; the pre-bound reference still points to the original.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "import datetime\n\ndef get_date():\n    return datetime.datetime.now().date()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "import time_machine\nfrom datetime import datetime\n\n@time_machine.travel('2024-01-01')\ndef test_date():\n    assert datetime.now().date().isoformat() == '2024-01-01'",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-29",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}