Skip to content

[BUG]: patch_all breaks freezegun in class-based tests #13991

@raylu

Description

@raylu

Tracer Version(s)

2.18.0+

Python Version(s)

3.12.5

Pip Version(s)

uv 0.6.9

Bug Report

running the test below with pytest fails the class-based test but passes on the function-based test

python -m unittest only runs the class-based test which also fails

I believe this is caused by 4ca6009 (#11406)

Reproduction Code

import time
import unittest

import ddtrace
import freezegun

ddtrace.patch_all()


class FGTest(unittest.TestCase):
    def test_fg_inside(self) -> None:
        with freezegun.freeze_time("2000-01-02T03:04:05Z"):
            assert time.time() == 946782245  # fails


def test_fg_outside() -> None:
    with freezegun.freeze_time("2000-01-02T03:04:05Z"):
        assert time.time() == 946782245  # passes

Error Logs

$ pytest tests/fg.py -v
[2025-07-14 14:49:12] tests/fg.py::FGTest::test_fg FAILED            [ 50%]
[2025-07-14 14:49:12] tests/fg.py::test_fg_without_basictest PASSED  [100%]
AssertionError: assert 1752529952.1958551 == 946782245
$ python3 -m unittest tests.fg -v
API client not initialized, disabling coverage collection and test skipping
test_fg (tests.fg.FGTest.test_fg) ... FAIL

Libraries in Use

freezegun 1.2.2

Operating System

Linux 690ffe62398b 6.14.10-orbstack-00291-g1b252bd3edea #1 SMP Sat Jun 7 02:45:18 UTC 2025 aarch64 aarch64 aarch64 GNU/Linux

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions