DET006infoPro

datetime-now-usage

datetime.now() makes code non-deterministic and hard to test

Applies to: Go, JavaScript, Python, Ruby, Rust, TypeScript

Why this matters

Using datetime.now() directly makes your code depend on the current time, which makes tests unreliable and caching impossible. Inject the time as a parameter or use a clock abstraction that can be mocked.

Catch it before it ships

pip install stablestack # or: npx stablestackstablestack # scans your project, DET006 includedstablestack explain DET006

DET006 is part of the Pro rule set. See pricing — the free tier ships 24 checks with no signup.

False positive in your codebase? Suppress a single line with # noqa: DET006