From 336d6f04e94efebcefb5574d0c8d487bcb0d187e Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 20 Jan 2025 08:54:30 -0800 Subject: [PATCH] Python: Improve refleak checker for Python 3.12. Each call to `unittest.TestResult.addDuration` increases the total refcount. The refleak checker now mocks this function to get consistent values. PiperOrigin-RevId: 717548068 --- python/google/protobuf/internal/testing_refleaks.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/google/protobuf/internal/testing_refleaks.py b/python/google/protobuf/internal/testing_refleaks.py index ca0f0b96d140a..a05ecf29f557e 100644 --- a/python/google/protobuf/internal/testing_refleaks.py +++ b/python/google/protobuf/internal/testing_refleaks.py @@ -37,6 +37,9 @@ def addFailure(self, test, error): def addSkip(self, test, reason): pass + def addDuration(self, test, duration): + pass + class ReferenceLeakCheckerMixin(object): """A mixin class for TestCase, which checks reference counts.""" @@ -59,7 +62,7 @@ def run(self, result=None): super(ReferenceLeakCheckerMixin, self).run(result=result) super(ReferenceLeakCheckerMixin, self).run(result=result) - oldrefcount = 0 + oldrefcount = 0 # pylint: disable=unused-variable but needed for refcounts. local_result = LocalTestResult(result) num_flakes = 0