{
  "id": "python/pytest-freezegun-time-not-frozen",
  "signature": "AssertionError: assert datetime.datetime(2025, 1, 15, 10, 30) == datetime.datetime(2024, 6, 1, 0, 0)\n  # expected freeze_time('2024-06-01') to apply",
  "signature_zh": "AssertionError：assert datetime.datetime(2025, 1, 15, 10, 30) == datetime.datetime(2024, 6, 1, 0, 0)\n  # 预期 freeze_time('2024-06-01') 会生效",
  "regex": "AssertionError:\\ assert\\ datetime\\.datetime\\(2025,\\ 1,\\ 15,\\ 10,\\ 30\\)\\ ==\\ datetime\\.datetime\\(2024,\\ 6,\\ 1,\\ 0,\\ 0\\)\\\n\\ \\ \\#\\ expected\\ freeze_time\\('2024\\-06\\-01'\\)\\ to\\ apply",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The code under test imported datetime or time functions before freeze_time patched them, or uses a C-extension clock (e.g., time.monotonic_ns via numpy) that freezegun cannot intercept. Also common when the module does 'from datetime import datetime' and freezegun patches the class attribute incorrectly.",
  "root_cause_type": "generic",
  "root_cause_zh": "被测代码在 freeze_time 修补之前导入了 datetime 或 time 函数，或者使用了 freezegun 无法拦截的 C 扩展时钟（例如通过 numpy 的 time.monotonic_ns）。当模块执行 'from datetime import datetime' 时也常见。",
  "versions": [
    {
      "version": "1.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Nested freezes raise or silently override; the innermost wins, but the outer reference was already captured.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Sleep does not retroactively patch already-imported names; the test still sees real time.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from freezegun import freeze_time\n\n@freeze_time('2024-06-01')\ndef test_expiry():\n    # myapp/utils.py does: from datetime import datetime\n    # freezegun patches datetime.datetime, so this works\n    assert is_expired(datetime(2024, 5, 31))",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def is_expired(now=None):\n    now = now or datetime.now(timezone.utc)\n    return now > EXPIRY\n\ndef test_expiry():\n    assert is_expired(now=datetime(2024, 5, 31, tzinfo=timezone.utc))",
      "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": "partial",
  "first_seen": "2024-09-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}