python config_error ai_generated true

Failed: Fixture "frozen_time" called directly. Use "freezer" instead.

ID: python/pytest-freeze-time-fixture-conflict

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2025-04-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.3 active — — —
0.9 active — — —

Root Cause

pytest-freezegun/freezegun-time plugin exposes `frozen_time` as a low-level helper; tests must request `freezer` (the fixture) which manages freeze/thaw lifecycle.

generic

中文

pytest-freezegun/freezegun-time 插件将 `frozen_time` 作为底层辅助对象暴露;测试必须请求 `freezer`(fixture),由它管理冻结/解冻生命周期。

Workarounds

  1. 95% success
    Request the freezer fixture:
    
    def test_expiry(freezer):
        freezer.move_to('2024-01-01')
        assert is_expired()
  2. 92% success
    Or use the decorator form:
    
    from freezegun import freeze_time
    
    @freeze_time('2024-01-01')
    def test_expiry(): ...

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The plugin detects direct access and raises the same failure.

  2. 80% fail

    Bypasses the fixture and leaves time frozen across other tests, causing cascading failures.