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

When freezegun is used at a class level, the pytest durations report shows invalid times #433

Closed
stevenbharris opened this issue Dec 1, 2021 · 1 comment · Fixed by #460

Comments

@stevenbharris
Copy link

Here's a real example with fake paths illustrating the problem:

============================ slowest test durations ============================
1355132.16s teardown application/path/test_security_record
61.27s setup    application/path/test_viewing_client_statements
60.38s setup    application/path/test_start_date
60.23s setup    application/path/test_send
...

1355132.16s corresponds to over 15 days.

I suspect that the pytest durations report logic is relying on datetime.datetime.now() which is patched by freezegun resulting in the report showing incorrect durations.

I don't think this issue is w/in freezegun but it does result in the above reported undesirable side effect.

@DavidS-cloud
Copy link
Contributor

DavidS-cloud commented Aug 1, 2022

Yeah, can confirm. I've been running into this too, here's my --junitxml results with class-level freeze_time:

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
    <testsuite errors="0" failures="0" hostname="0fa262bea4da" name="pytest" skipped="0" tests="8" time="7.787" timestamp="2022-08-01T13:26:39.258110">
        <testcase classname="foo.TestViewSet" name="test_1_something" time="1652811173.470" />
        <testcase classname="foo.TestViewSet" name="test_2_something" time="0.000" />
        <testcase classname="foo.TestViewSet" name="test_3_something" time="0.000" />
        <testcase classname="foo.TestViewSet" name="test_4_something" time="0.000" />
        <testcase classname="foo.TestViewSet" name="test_5_something" time="0.000" />
        <testcase classname="foo.TestViewSet" name="test_6_something" time="0.000" />
        <testcase classname="foo.TestViewSet" name="test_7_something" time="0.000" />
        <testcase classname="foo.TestViewSet" name="test_8_something" time="-1652811169.381" />
    </testsuite>
</testsuites>

and with method-level freeze_time:

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
    <testsuite errors="0" failures="0" hostname="51f569add280" name="pytest" skipped="0" tests="8" time="7.886" timestamp="2022-08-01T13:29:47.579062">
        <testcase classname="foo.TestViewSet" name="test_1_something" time="3.713" />
        <testcase classname="foo.TestViewSet" name="test_2_something" time="0.085" />
        <testcase classname="foo.TestViewSet" name="test_3_something" time="0.081" />
        <testcase classname="foo.TestViewSet" name="test_4_something" time="0.081" />
        <testcase classname="foo.TestViewSet" name="test_5_something" time="0.074" />
        <testcase classname="foo.TestViewSet" name="test_6_something" time="0.055" />
        <testcase classname="foo.TestViewSet" name="test_7_something" time="0.082" />
        <testcase classname="foo.TestViewSet" name="test_8_something" time="0.048" />
    </testsuite>
</testsuites>

DavidS-cloud added a commit to DavidS-cloud/freezegun that referenced this issue Aug 1, 2022
This avoids class-level decorator usage messing with pytest timings.

This fixes spulec#433.
@boxed boxed closed this as completed in #460 Aug 1, 2022
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

Successfully merging a pull request may close this issue.

2 participants