summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-08-08 22:18:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-08-08 22:18:46 (GMT)
commit696e03553b9e455bd6729cee5a8be43a2924f537 (patch)
tree1921798050d0e6f60e64e0a8408690398d2b82f6 /Lib
parent2e5f1178ac55c032982c69f4f4dd70c19f9fa46e (diff)
downloadcpython-696e03553b9e455bd6729cee5a8be43a2924f537.zip
cpython-696e03553b9e455bd6729cee5a8be43a2924f537.tar.gz
cpython-696e03553b9e455bd6729cee5a8be43a2924f537.tar.bz2
Issue #477863: Print a warning at shutdown if gc.garbage is not empty.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_gc.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index 3b7df99..fba9583 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -1,5 +1,5 @@
import unittest
-from test.support import verbose, run_unittest
+from test.support import verbose, run_unittest, strip_python_stderr
import sys
import gc
import weakref
@@ -466,6 +466,42 @@ class GCTests(unittest.TestCase):
# would be damaged, with an empty __dict__.
self.assertEqual(x, None)
+ def test_garbage_at_shutdown(self):
+ import subprocess
+ code = """if 1:
+ import gc
+ class X:
+ def __init__(self, name):
+ self.name = name
+ def __repr__(self):
+ return "<X %%r>" %% self.name
+ def __del__(self):
+ pass
+
+ x = X('first')
+ x.x = x
+ x.y = X('second')
+ del x
+ if %d:
+ gc.set_debug(gc.DEBUG_UNCOLLECTABLE)
+ """
+ def run_command(code):
+ p = subprocess.Popen([sys.executable, "-c", code],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ self.assertEqual(p.returncode, 0)
+ self.assertEqual(stdout.strip(), b"")
+ return strip_python_stderr(stderr)
+
+ stderr = run_command(code % 0)
+ self.assertIn(b"gc: 2 uncollectable objects at shutdown", stderr)
+ self.assertNotIn(b"[<X 'first'>, <X 'second'>]", stderr)
+ # With DEBUG_UNCOLLECTABLE, the garbage list gets printed
+ stderr = run_command(code % 1)
+ self.assertIn(b"gc: 2 uncollectable objects at shutdown", stderr)
+ self.assertIn(b"[<X 'first'>, <X 'second'>]", stderr)
+
class GCTogglingTests(unittest.TestCase):
def setUp(self):
gc.enable()