Add pytest-freezegun support to migration CLI
Description
The migration CLI could potentially rewrite use of the freezer fixture and freeze_time marker from pytest-freezegun.
The migration CLI could potentially rewrite
Which migration CLI are you referring to here? Are you referring to django-upgrade?
https://time-machine.readthedocs.io/en/latest/migration.html#migration-cli
🤯 NICE!
Issue with this: thefreezer-gun pytest fixture is called freezer and the import is called freeze_gun, ruff doesn't complain about you reusing the name of the name. With time_machine we run into this issue.
we can rename the fixure tm, delorian, chrono_device, chrono, flux_capacitor, temporal_device.... what do you think?
import freezegun
def test_before_a():
with freezegun.freeze_time(datetime.now() - timedelta(days=100)):
....
@pytest.mark.django_db
def test_before_b(freezer):
freezer.move_to("2000-01-01")
....
currently:
import time_machine
def test_after_b():
with time_machine.travel(datetime.now() - timedelta(days=100), tick=False):
....
@pytest.mark.django_db
def test_after_b(time_machine):
time_machine.travel("2000-01-01", tick=False)
....
While I agree, this should not have happened in the first place, this causes friction at the moment.
I don't want to rename the fixture solely to make it easier to write a migration CLI that works in all circumstances.
The CLI is a best-effort tool, aiming to be slightly better than find/replace. We should be fine with leaving some cases where it doesn't work great. In your example, the user can fix things up for the Ruff rule by moving import time_machine into the functions that use it.
I can keep the
time_machinefixture name, and detect thatfreezeris being used AND alsoimport freeze_gunand simply turn everything into a fixture... otherwise it will do the default behavior.. thoughts?
You're proposing rewriting tests from direct module usage to fixture usage? I wouldn't feel comfortable adding that, I think it would be too hard to guarantee correctness in all situations.
I think a basic fixture rewrite, even if it sometimes causes name collisions, will be fine.
I could do: good enough then, convert 1-to-1, the linter could then fail, but that would be their problem to solve.
speaking from my own bias point of view though, i have a large code base that i'm using it as a guinea pig and i was trying to remove work for myself.. but yeah ill simply it
Just noticed that this doesn't work, definitely would be helpful.