freezegun

Python library for mocking datetime in tests. freezegun patches Python's datetime module to return a fixed time, making time-dependent tests deterministic. Works as a decorator, context manager, or pytest fixture. Patches datetime.datetime, datetime.date, datetime.time, time.time(), time.localtime(), time.gmtime(), and time.strftime() consistently.

Evaluated Mar 06, 2026 (0d ago) v1.4+
Homepage ↗ Repo ↗ Developer Tools python testing datetime mocking time freeze pytest
⚙ Agent Friendliness
67
/ 100
Can an agent use this?
🔒 Security
98
/ 100
Is it safe for agents?
⚡ Reliability
90
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
80
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
88
Secret Handling
100

Testing library — no network access or credentials. Only manipulates Python's datetime module.

⚡ Reliability

Uptime/SLA
100
Version Stability
88
Breaking Changes
85
Error Recovery
85
AF Security Reliability

Best When

You need to freeze or travel through time in Python tests to make time-dependent logic deterministic.

Avoid When

You need fine-grained async time control or testing real sleep durations — use time-machine or mock.patch for specific cases.

Use Cases

  • Test agent scheduling logic that depends on current time with deterministic fixed-time assertions
  • Verify agent expiration, TTL, and time-window logic by freezing time at specific moments
  • Test agent behavior at edge cases (end of month, leap year, DST transition) by controlling time
  • Make agent test suites deterministic by eliminating datetime.now() variability
  • Test agent retry backoff calculations that use time.time() for elapsed time measurement

Not For

  • Async tests requiring time manipulation — time-machine is better for async/trio tests
  • Performance testing — freezegun adds overhead to datetime calls
  • Testing actual clock-based functionality (sleep, actual timeouts) — freezegun doesn't speed up real time.sleep()

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Local testing library — no authentication.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

Completely free and open source.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • freezegun doesn't freeze C extensions that call system time directly — some libraries (e.g., some DB drivers) use C-level time calls not patched by freezegun
  • Async tests require pytest-freezegun or explicit freezegun patching of asyncio event loop time — standard @freeze_time may not work with async code
  • time.sleep() still blocks real time when frozen — freezegun doesn't make sleep() instant; use unittest.mock.patch('time.sleep') for that
  • Timezone-aware datetime objects need timezone specified in freeze_time() — naive datetime freezing can produce unexpected UTC vs local time results
  • tick=True mode advances time in real-time from the frozen start — useful for testing time advancement but adds test complexity
  • Some third-party libraries import datetime directly (from datetime import datetime) — freezegun may not patch these; check with ignore_list parameter

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for freezegun.

$99

Scores are editorial opinions as of 2026-03-06.

5220
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered