question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

as_arg adds frozen_time argument to front of list of arguments

See original GitHub issue

Currently 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:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
boxedcommented, Oct 30, 2018

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?

1reaction
boxedcommented, May 27, 2020

I haven’t made it. I would welcome a PR. Seems like it should be an easy change.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found