summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-04-12 00:42:18 -0700
committerEric Wieser <wieser.eric@gmail.com>2018-04-12 01:26:17 -0700
commitd21ec05eb006c072e4fd8c5fe1bd63619378aded (patch)
tree2512081fe1e139720c5576102631626b6ce299d8 /numpy/testing/_private/utils.py
parent5c3d52405b647bc69185f657ed4c180c02ac14f7 (diff)
downloadnumpy-d21ec05eb006c072e4fd8c5fe1bd63619378aded.tar.gz
ENH: Show the full list of leaked objects
An example output for the test added in the previous commit is: AssertionError: Reference cycles were found when calling make_cycle: 1 objects were collected, of which 1 are shown below: list object with id=2279664872136: [<Recursion on list with id=2279664872136>, <Recursion on list with id=2279664872136>]
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index 4a113f12e..0c9fd644c 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -15,6 +15,7 @@ import shutil
import contextlib
from tempfile import mkdtemp, mkstemp
from unittest.case import SkipTest
+import pprint
from numpy.core import(
float32, empty, arange, array_repr, ndarray, isnat, array)
@@ -2285,20 +2286,38 @@ def _assert_no_gc_cycles_context(name=None):
assert_(gc.isenabled())
gc.disable()
+ gc_debug = gc.get_debug()
try:
gc.collect()
+ gc.set_debug(gc.DEBUG_SAVEALL)
yield
# gc.collect returns the number of unreachable objects in cycles that
# were found -- we are checking that no cycles were created in the context
n_objects_in_cycles = gc.collect()
+ objects_in_cycles = gc.garbage[:]
finally:
+ del gc.garbage[:]
+ gc.set_debug(gc_debug)
gc.enable()
if n_objects_in_cycles:
name_str = " when calling %s" % name if name is not None else ""
raise AssertionError(
- "Reference cycles were found{}: {} objects were collected"
- .format(name_str, n_objects_in_cycles))
+ "Reference cycles were found{}: {} objects were collected, "
+ "of which {} are shown below:{}"
+ .format(
+ name_str,
+ n_objects_in_cycles,
+ len(objects_in_cycles),
+ ''.join(
+ "\n {} object with id={}:\n {}".format(
+ type(o).__name__,
+ id(o),
+ pprint.pformat(o).replace('\n', '\n ')
+ ) for o in objects_in_cycles
+ )
+ )
+ )
def assert_no_gc_cycles(*args, **kwargs):