Skip to content

refactor(tests): replace deprecated pytest-freezegun with time-machine - #1036

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

refactor(tests): replace deprecated pytest-freezegun with time-machine#1036
armorbreak001 wants to merge 1 commit into
scanapi:mainfrom
armorbreak001:fix/replace-pytest-freezegun-with-time-machine

Conversation

@armorbreak001

Copy link
Copy Markdown
Contributor

Summary

Replace the unmaintained pytest-freezegun (last release 2020) with time-machine, which is actively maintained and provides equivalent time-freezing capabilities.

Problem

pytest-freezegun generates hundreds of DeprecationWarning on Python 3.12+ because it relies on the deprecated distutils.version.LooseVersion:

.venv/lib/python3.12/site-packages/pytest_freezegun.py:17: 778 DeprecationWarnings
  DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.

Changes

  • pyproject.toml: Replace pytest-freezegun==0.4.2 with time-machine>=2.14.0
  • tests/unit/test_reporter.py:
    • Replace freezegun.api.FakeDatetime with datetime.datetime
    • Replace @mark.freeze_time() with @time_machine.travel()
  • tests/unit/test_session.py:
    • Replace @mark.freeze_time() with @time_machine.travel()
    • Replace freezer.move_to() with time_machine fixture

Testing

All 186 tests pass with zero deprecation warnings.

Closes #957

pytest-freezegun is unmaintained (last release 2020) and generates
hundreds of DeprecationWarning on Python 3.12+ due to its reliance
on distutils.version.LooseVersion.

This commit replaces it with time-machine, which is actively maintained
and provides equivalent time-freezing capabilities:

- Replace pytest-freezegun dependency with time-machine>=2.14.0
- Replace @mark.freeze_time() decorators with @time_machine.travel()
- Replace FakeDatetime with datetime.datetime
- Replace freezegun's freezer fixture with time_machine fixture

All 186 tests pass with zero deprecation warnings from this change.

Closes scanapi#957
@armorbreak001
armorbreak001 requested review from a team as code owners August 1, 2026 06:50
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

📌 Esta mensagem está tanto em português quanto em inglês (mais abaixo) — assim todo mundo consegue acompanhar!
📌 This message is in both Portuguese and English (further down) — so everyone can follow along!

🇧🇷 Português

👋 Olá!

Este PR está obsoleto porque ficou aberto por 30 dias sem atividade. Remova o rótulo de stale ou comente, caso contrário ele será fechado em 15 dias.

🇬🇧 English

Hey there! 👋

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 15 days.

@github-actions github-actions Bot added the Stale label Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace deprecated pytest-freezegun with time-machine

1 participant