Skip to content

Commit b2ff81f

Browse files
authored
Merge pull request numpy#15675 from charris/backport-15329
TST: move _no_tracing to testing._private
2 parents a358ebd + fbbf7c6 commit b2ff81f

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

numpy/core/tests/test_multiarray.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
assert_allclose, IS_PYPY, HAS_REFCOUNT, assert_array_less, runstring,
4747
temppath, suppress_warnings, break_cycles,
4848
)
49+
from numpy.testing._private.utils import _no_tracing
4950
from numpy.core.tests._locales import CommaDecimalPointLocale
5051

5152
# Need to test an object that does not fully implement math interface
@@ -96,26 +97,6 @@ def _aligned_zeros(shape, dtype=float, order="C", align=None):
9697
data.fill(0)
9798
return data
9899

99-
def _no_tracing(func):
100-
"""
101-
Decorator to temporarily turn off tracing for the duration of a test.
102-
Needed in tests that check refcounting, otherwise the tracing itself
103-
influences the refcounts
104-
"""
105-
if not hasattr(sys, 'gettrace'):
106-
return func
107-
else:
108-
@functools.wraps(func)
109-
def wrapper(*args, **kwargs):
110-
original_trace = sys.gettrace()
111-
try:
112-
sys.settrace(None)
113-
return func(*args, **kwargs)
114-
finally:
115-
sys.settrace(original_trace)
116-
return wrapper
117-
118-
119100

120101
class TestFlags(object):
121102
def setup(self):

numpy/core/tests/test_regression.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
assert_raises_regex, assert_warns, suppress_warnings,
1717
_assert_valid_refcount, HAS_REFCOUNT,
1818
)
19+
from numpy.testing._private.utils import _no_tracing
1920
from numpy.compat import asbytes, asunicode, long, pickle
20-
from test.support import no_tracing
2121

2222
try:
2323
RecursionError
@@ -1317,7 +1317,7 @@ def test_void_scalar_constructor(self):
13171317
assert_(pickle.loads(
13181318
pickle.dumps(test_record, protocol=proto)) == test_record)
13191319

1320-
@no_tracing
1320+
@_no_tracing
13211321
def test_blasdot_uninitialized_memory(self):
13221322
# Ticket #950
13231323
for m in [0, 1, 2]:

numpy/testing/_private/utils.py

+21
Original file line numberDiff line numberDiff line change
@@ -2476,3 +2476,24 @@ def _get_mem_available():
24762476
return info['memfree'] + info['cached']
24772477

24782478
return None
2479+
2480+
2481+
def _no_tracing(func):
2482+
"""
2483+
Decorator to temporarily turn off tracing for the duration of a test.
2484+
Needed in tests that check refcounting, otherwise the tracing itself
2485+
influences the refcounts
2486+
"""
2487+
if not hasattr(sys, 'gettrace'):
2488+
return func
2489+
else:
2490+
@wraps(func)
2491+
def wrapper(*args, **kwargs):
2492+
original_trace = sys.gettrace()
2493+
try:
2494+
sys.settrace(None)
2495+
return func(*args, **kwargs)
2496+
finally:
2497+
sys.settrace(original_trace)
2498+
return wrapper
2499+

0 commit comments

Comments
 (0)