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
- Add freezegun to the project test dependencies (test extra or dev group).
- Ensure the CI install step installs that group.
- 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
Python "hypothesis Flaky / DeadlineExceeded" in CIFix "hypothesis.errors.Flaky" and "DeadlineExceeded" failures in CI - a property test either produced inconsi…
Python "factory_boy DjangoModelFactory not registered" in CIFix factory_boy errors where a DjangoModelFactory is not wired up in CI - the factory is unregistered with py…
freezegun Time Not Frozen / "ModuleNotFoundError" in CIFix freezegun tests where time is not frozen in CI - a C-extension datetime, a non-patched time source, or th…