Skip to content
Latchkey

Python "freezegun ImportError / not installed" in CI

Importing from freezegun import freeze_time fails with ModuleNotFoundError when freezegun is not installed in the CI environment, typically because it is only listed as a local/dev dependency that CI does not install.

What this error means

Test collection fails with "ModuleNotFoundError: No module named 'freezegun'" at the import line of a time-dependent test.

pytest
ModuleNotFoundError: No module named 'freezegun'

Common causes

freezegun is missing from the CI dependency set

It is installed locally but not declared in the test extras/requirements CI installs.

A test extras group is not installed in CI

The job installed only runtime deps, not the test group that contains freezegun.

How to fix it

Declare freezegun in the test dependencies and install them

  1. Add freezegun to the project test dependencies (test extra or dev group).
  2. Ensure the CI install step installs that group.
  3. Pin a version so behavior is stable across runs.
pyproject.toml
[project.optional-dependencies]
test = ["pytest", "freezegun>=1.4"]

How to prevent it

  • Keep all test-only imports declared in the test dependency group.
  • Install the test extras in CI explicitly.
  • Pin test tool versions.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →