Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect test duration recorded when test uses freezegun #16

Closed
petedmarsh opened this issue Jun 15, 2017 · 2 comments
Closed

Incorrect test duration recorded when test uses freezegun #16

petedmarsh opened this issue Jun 15, 2017 · 2 comments

Comments

@petedmarsh
Copy link
Contributor

I came across this project yesterday and I tried it out on my Django project, I got some strange output:

77450953.5910s test_a (some.TestCase)
45914963.3745s test_b (other.TestCase)
...
1.6083s test_c (final.TestCase)

Now, my some of my tests are on the slow side but they don't take > 2 years to run!

I remember that some of my test cases use freezegun to test date/time sensitive code - I think that's likely the cause.

In my case other.TestCase.test_b uses freezegun:

class TestCase(TestCase):
    @freeze_time('2016-11-14 10:00')
    def test_b(self):
        #...

but some.TestCase.test_a does not - and when I run other.TestCase.test_b in isolation I get a reasonable recorded duration, so it seems that using freezegun in one test affects the recorded time of another.

@mjhea0
Copy link
Contributor

mjhea0 commented Jun 15, 2017

Thanks for letting me know. I need to look at freeze gun and figure out what's going on. Give me a few days.

@petedmarsh
Copy link
Contributor Author

petedmarsh commented Jun 15, 2017 via email

petedmarsh added a commit to petedmarsh/django-slow-tests that referenced this issue Jun 16, 2017
freezegun is a Python library used to set the date/time returned by
the Python date/time functions to make testing time-sensitive code
easier.

time.time() is used here to measure the duration of test cases, if
freezegun was in use then the time returned by this could be the
time the test had set up, rather than the actual time. This lead to
test durations being reported as negative (if frozen time is in the
past), or much longer than expected (if fronzen time is in the
future).

freezegun exposes the unmodified time.time() via an alias. This
changes TimingSuite so that it uses this alias if freezegun is
installed.
petedmarsh added a commit to petedmarsh/django-slow-tests that referenced this issue Jun 16, 2017
freezegun is a Python library used to set the date/time returned by
the Python date/time functions to make testing time-sensitive code
easier.

time.time() is used here to measure the duration of test cases, if
freezegun was in use then the time returned by this could be the
time the test had set up, rather than the actual time. This lead to
test durations being reported as negative (if frozen time is in the
past), or much longer than expected (if fronzen time is in the
future).

freezegun exposes the unmodified time.time() via an alias. This
changes TimingSuite so that it uses this alias if freezegun is
installed.
petedmarsh added a commit to petedmarsh/django-slow-tests that referenced this issue Jun 16, 2017
freezegun is a Python library used to set the date/time returned by
the Python date/time functions to make testing time-sensitive code
easier.

time.time() is used here to measure the duration of test cases, if
freezegun was in use then the time returned by this could be the
time the test had set up, rather than the actual time. This lead to
test durations being reported as negative (if frozen time is in the
past), or much longer than expected (if fronzen time is in the
future).

freezegun exposes the unmodified time.time() via an alias. This
changes TimingSuite so that it uses this alias if freezegun is
installed.
petedmarsh added a commit to petedmarsh/django-slow-tests that referenced this issue Jun 16, 2017
freezegun is a Python library used to set the date/time returned by
the Python date/time functions to make testing time-sensitive code
easier.

time.time() is used here to measure the duration of test cases, if
freezegun was in use then the time returned by this could be the
time the test had set up, rather than the actual time. This lead to
test durations being reported as negative (if frozen time is in the
past), or much longer than expected (if fronzen time is in the
future).

freezegun exposes the unmodified time.time() via an alias. This
changes TimingSuite so that it uses this alias if freezegun is
installed.
@mjhea0 mjhea0 closed this as completed in 91202a6 Jun 17, 2017
mjhea0 added a commit that referenced this issue Jun 17, 2017
Fixed #16 - Incorrect test duration with freezegun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants