as_arg adds frozen_time argument to front of list of arguments
See original GitHub issueCurrently the following code does not work with test classes (Django, etc).
https://github.com/spulec/freezegun/blob/master/freezegun/api.py#L669
That line does the following
result = func(time_factory, *args, **kwargs)
That is incompatible with self
being the first param to class methods and it behaves differently than most other decorators, which add their argument to the end, not the beginning. Here is an example that doesn’t work
from django.test import TestCase
from freezegun import freeze_time
class MyTest(TestCase):
@freeze_time('2016-11-01', as_arg=True)
def test_something_with_time(self, time_factory):
# freeze_time overrides self instead of time_factory
# self is now the time_factory variable
print(self) # <TimeFactory>
print(time_factory) # <MyTestCase>
It should do this instead.
result = func(*args, time_factory, **kwargs)
This is a backwards incompatible change, but will allow the decorator to be used with class based tests. Would you be open to accepting a PR that makes this breaking change?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:16 (1 by maintainers)
Top Results From Across the Web
Date & Time - 4.x - CakePHP Cookbook
The FrozenTime class constructor can take any parameter that the internal DateTimeImmutable PHP class can. When passing a number or numeric string, it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve thought this through a bit more now, and think it’s better with a new as_kwarg option. Then there is no backwards compatibility problem and it’s a bit more elegant too I think. What do you think?
I haven’t made it. I would welcome a PR. Seems like it should be an easy change.