Skip to content

Commit 8907efc

Browse files
Integrate the refleak run check into regrtest and test.support
1 parent 1fc2443 commit 8907efc

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

Lib/test/libregrtest/refleak.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from test import support
77
from test.support import os_helper
8+
from test.support import refleak_helper
89

910
from .runtests import HuntRefleak
1011
from .utils import clear_caches
@@ -96,7 +97,12 @@ def get_pooled_int(value):
9697
support.gc_collect()
9798

9899
for i in rep_range:
99-
results = test_func()
100+
current = refleak_helper._hunting_for_refleaks
101+
refleak_helper._hunting_for_refleaks = True
102+
try:
103+
results = test_func()
104+
finally:
105+
refleak_helper._hunting_for_refleaks = current
100106

101107
dash_R_cleanup(fs, ps, pic, zdc, abcs)
102108
support.gc_collect()

Lib/test/support/refleak_helper.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
Utilities for changing test behaviour while hunting
3+
for refleaks
4+
"""
5+
6+
_hunting_for_refleaks = False
7+
def hunting_for_refleaks():
8+
return _hunting_for_refleaks

Lib/test/test_socket.py

+3-26
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from test.support import os_helper
44
from test.support import socket_helper
55
from test.support import threading_helper
6+
from test.support import refleak_helper
67

78
import _thread as thread
89
import array
@@ -52,27 +53,6 @@
5253
except ImportError:
5354
_socket = None
5455

55-
_hunting_for_refleaks = None
56-
def hunting_for_refleaks():
57-
"""
58-
Return true iff running tests while hunting for refleaks
59-
"""
60-
from test.libregrtest.runtests import RunTests
61-
import gc
62-
63-
global _hunting_for_refleaks
64-
65-
if _hunting_for_refleaks is None:
66-
for value in gc.get_objects():
67-
if isinstance(value, RunTests):
68-
_hunting_for_refleaks = (value.hunt_refleak is not None)
69-
break
70-
else:
71-
_hunting_for_refleaks = False
72-
73-
return _hunting_for_refleaks
74-
75-
7656
def skipForRefleakHuntinIf(condition, issueref):
7757
if not condition:
7858
def decorator(f):
@@ -83,15 +63,15 @@ def decorator(f):
8363
def decorator(f):
8464
@contextlib.wraps(f)
8565
def wrapper(*args, **kwds):
86-
if hunting_for_refleaks():
66+
if refleak_helper.hunting_for_refleaks():
8767
raise unittest.SkipTest(f"ignore while hunting for refleaks, see {issueref}")
8868

8969
return f(*args, **kwds)
9070

9171
def client_skip(f):
9272
@contextlib.wraps(f)
9373
def wrapper(*args, **kwds):
94-
if hunting_for_refleaks():
74+
if refleak_helper.hunting_for_refleaks():
9575
return
9676

9777
return f(*args, **kwds)
@@ -3886,9 +3866,6 @@ def testCmsgTrunc0(self):
38863866

38873867
@testCmsgTrunc0.client_skip
38883868
def _testCmsgTrunc0(self):
3889-
if sys.platform == "darwin" and hunting_for_refleaks():
3890-
return
3891-
38923869
self.createAndSendFDs(1)
38933870

38943871
# Check that no ancillary data is returned for various non-zero

0 commit comments

Comments
 (0)