Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TST: move _no_tracing to testing._private #15675

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

Merged
merged 1 commit into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
assert_allclose, IS_PYPY, HAS_REFCOUNT, assert_array_less, runstring,
temppath, suppress_warnings, break_cycles,
)
from numpy.testing._private.utils import _no_tracing
from numpy.core.tests._locales import CommaDecimalPointLocale

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

def _no_tracing(func):
"""
Decorator to temporarily turn off tracing for the duration of a test.
Needed in tests that check refcounting, otherwise the tracing itself
influences the refcounts
"""
if not hasattr(sys, 'gettrace'):
return func
else:
@functools.wraps(func)
def wrapper(*args, **kwargs):
original_trace = sys.gettrace()
try:
sys.settrace(None)
return func(*args, **kwargs)
finally:
sys.settrace(original_trace)
return wrapper



class TestFlags(object):
def setup(self):
Expand Down
4 changes: 2 additions & 2 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
assert_raises_regex, assert_warns, suppress_warnings,
_assert_valid_refcount, HAS_REFCOUNT,
)
from numpy.testing._private.utils import _no_tracing
from numpy.compat import asbytes, asunicode, long, pickle
from test.support import no_tracing

try:
RecursionError
Expand Down Expand Up @@ -1317,7 +1317,7 @@ def test_void_scalar_constructor(self):
assert_(pickle.loads(
pickle.dumps(test_record, protocol=proto)) == test_record)

@no_tracing
@_no_tracing
def test_blasdot_uninitialized_memory(self):
# Ticket #950
for m in [0, 1, 2]:
Expand Down
21 changes: 21 additions & 0 deletions numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,3 +2476,24 @@ def _get_mem_available():
return info['memfree'] + info['cached']

return None


def _no_tracing(func):
"""
Decorator to temporarily turn off tracing for the duration of a test.
Needed in tests that check refcounting, otherwise the tracing itself
influences the refcounts
"""
if not hasattr(sys, 'gettrace'):
return func
else:
@wraps(func)
def wrapper(*args, **kwargs):
original_trace = sys.gettrace()
try:
sys.settrace(None)
return func(*args, **kwargs)
finally:
sys.settrace(original_trace)
return wrapper