Skip to content

chore(deps): replace pytest-freezegun with time-machine#962

Open
klouds27 wants to merge 1 commit into
scanapi:mainfrom
klouds27:fix/957-replace-pytest-freezegun-with-time-machine
Open

chore(deps): replace pytest-freezegun with time-machine#962
klouds27 wants to merge 1 commit into
scanapi:mainfrom
klouds27:fix/957-replace-pytest-freezegun-with-time-machine

Conversation

@klouds27

Copy link
Copy Markdown

Summary

  • Removes pytest-freezegun (unmaintained since 2020, generates 790 DeprecationWarnings on Python 3.12+ via distutils.version.LooseVersion)
  • Adds time-machine>=2.0,<3.0 as replacement
  • Migrates tests/unit/test_reporter.py and tests/unit/test_session.py to the new API

Migration notes

  • @mark.freeze_time(...) on individual methods → @time_machine.travel(..., tick=False) decorator
  • @mark.freeze_time(...) on a plain pytest class → autouse fixture with time_machine.travel context manager (class decorator only works on unittest.TestCase subclasses)
  • from freezegun.api import FakeDatetimefrom datetime import datetime (time-machine uses real datetime objects)
  • freezer.move_to(...) pattern → with time_machine.travel(...) as traveller: traveller.move_to(...)

Test plan

  • uv sync --extra dev installs time-machine==2.19.0 and removes pytest-freezegun/freezegun
  • make test → 388 passed, 1 skipped, 0 warnings

Closes #957

🤖 Generated with Claude Code

pytest-freezegun is unmaintained and generates 790 DeprecationWarnings
on Python 3.12+ due to its use of distutils.version.LooseVersion.

Replace it with time-machine, which is actively maintained and supports
modern Python. Adapt tests to use @time_machine.travel decorator and an
autouse fixture for class-level freezing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@klouds27 klouds27 requested review from a team as code owners May 24, 2026 00:17
Copilot AI review requested due to automatic review settings May 24, 2026 00:17

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for supporting ScanAPI, and congratulations on your first contribution! A project committer will shortly review your contribution.

In the mean time, if you haven't had a chance please skim over the First Pull Request Guide which all pull requests must adhere to.

We hope to see you around!

@github-actions github-actions Bot added the First Contribution First contribution to the project. label May 24, 2026

@camilamaia camilamaia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!! 🎉

Image

Could you also remove this line from the README.md?

- **pytest-freezegun==0.4.2**: This package is unmaintained and only 0.4.2 is available. Strict pin is required for test stability.

After your change, we don't have this restriction anymore, which is great.

Thanks!!

Comment thread pyproject.toml
"pytest>=9.0.3,<10.0.0",
"pytest-cov>=7.0.0,<8.0.0",
"pytest-freezegun==0.4.2", # Unmaintained; strict pin required for stability
"time-machine>=2.0,<3.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just noticed that the last stable version for time-machine is 3.2.0. Is there any specific reason to not pin the version range to something like >=3.0,<4.0 instead?

@camilamaia

camilamaia commented May 24, 2026

Copy link
Copy Markdown
Member

@klouds27 could you also please assign yourself to the issue you're working on? This helps avoid multiple people accidentally working on the same issue.

It’s very simple: just comment dibs on issue #957. That will automatically assign the issue to you, making it clear to everyone that you’re already working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First Contribution First contribution to the project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace deprecated pytest-freezegun with time-machine

2 participants