# AssertionError: assert '2026-03-01' == '2024-01-01'
  # 测试内 datetime.now() 未被冻结

- **ID:** `python/pytest-freeze-time-not-active`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

freezegun 的 freeze_time 装饰器在导入时补丁 datetime，但被测代码使用 'from datetime import datetime' 导入，在补丁之前就绑定了原始类。被补丁的模块级 datetime 未被使用。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.x | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   import datetime

def get_date():
    return datetime.datetime.now().date()
   ```
2. **** (88% 成功率)
   ```
   import time_machine
from datetime import datetime

@time_machine.travel('2024-01-01')
def test_date():
    assert datetime.now().date().isoformat() == '2024-01-01'
   ```

## 无效尝试

- **** — Time is not the issue; the reference is bound to the unpatched class regardless of duration. (80% 失败率)
- **** — time-machine also patches the datetime module; the pre-bound reference still points to the original. (70% 失败率)
