stderr = re.sub(br"\[\d+ refs, \d+ blocks\]\r?\n?", b"", stderr).strip()
return stderr
+requires_type_collecting = unittest.skipIf(hasattr(sys, 'getcounts'),
+ 'types are immortal if COUNT_ALLOCS is defined')
+
def args_from_interpreter_flags():
"""Return a list of command-line arguments reproducing the current
settings in sys.flags and sys.warnoptions."""
import unittest
from test.support import (verbose, refcount_test, run_unittest,
- strip_python_stderr, cpython_only, start_threads,
- temp_dir)
+ strip_python_stderr, cpython_only, start_threads,
+ temp_dir, requires_type_collecting)
from test.support.script_helper import assert_python_ok, make_script
import sys
del a
self.assertNotEqual(gc.collect(), 0)
+ @requires_type_collecting
def test_newinstance(self):
class A(object):
pass
stderr = run_command(code % "gc.DEBUG_SAVEALL")
self.assertNotIn(b"uncollectable objects at shutdown", stderr)
+ @requires_type_collecting
def test_gc_main_module_at_shutdown(self):
# Create a reference cycle through the __main__ module and check
# it gets collected at interpreter shutdown.
rc, out, err = assert_python_ok('-c', code)
self.assertEqual(out.strip(), b'__del__ called')
+ @requires_type_collecting
def test_gc_ordinary_module_at_shutdown(self):
# Same as above, but with a non-__main__ module.
with temp_dir() as script_dir:
""".format(iomod=iomod, kwargs=kwargs)
return assert_python_ok("-c", code)
+ @support.requires_type_collecting
def test_create_at_shutdown_without_encoding(self):
rc, out, err = self._check_create_at_shutdown()
if err:
else:
self.assertEqual("ok", out.decode().strip())
+ @support.requires_type_collecting
def test_create_at_shutdown_with_encoding(self):
rc, out, err = self._check_create_at_shutdown(encoding='utf-8',
errors='strict')
logging.setLoggerClass(logging.Logger)
self.assertEqual(logging.getLoggerClass(), logging.Logger)
+ @support.requires_type_collecting
def test_logging_at_shutdown(self):
# Issue #20037
code = """if 1:
# Test the module type
import unittest
import weakref
-from test.support import gc_collect
+from test.support import gc_collect, requires_type_collecting
from test.support.script_helper import assert_python_ok
import sys
gc_collect()
self.assertEqual(f().__dict__["bar"], 4)
+ @requires_type_collecting
def test_clear_dict_in_ref_cycle(self):
destroyed = []
m = ModuleType("foo")
self.assertEqual(r[-len(ends_with):], ends_with,
'{!r} does not end with {!r}'.format(r, ends_with))
+ @requires_type_collecting
def test_module_finalization_at_shutdown(self):
# Module globals and builtins should still be available during shutdown
rc, out, err = assert_python_ok("-c", "from test import final_a")
c = sys.getallocatedblocks()
self.assertIn(c, range(b - 50, b + 50))
+ @test.support.requires_type_collecting
def test_is_finalizing(self):
self.assertIs(sys.is_finalizing(), False)
# Don't use the atexit module because _Py_Finalizing is only set
check((1,2,3), vsize('') + 3*self.P)
# type
# static type: PyTypeObject
- s = vsize('P2n15Pl4Pn9Pn11PIP')
+ fmt = 'P2n15Pl4Pn9Pn11PIP'
+ if hasattr(sys, 'getcounts'):
+ fmt += '3n2P'
+ s = vsize(fmt)
check(int, s)
- s = vsize('P2n15Pl4Pn9Pn11PIP' # PyTypeObject
+ s = vsize(fmt + # PyTypeObject
'3P' # PyAsyncMethods
'36P' # PyNumberMethods
'3P' # PyMappingMethods
"""
import test.support
-from test.support import verbose, strip_python_stderr, import_module, cpython_only
+from test.support import (verbose, import_module, cpython_only,
+ requires_type_collecting)
from test.support.script_helper import assert_python_ok, assert_python_failure
import random
self.assertIn("ZeroDivisionError", err)
self.assertNotIn("Unhandled exception", err)
+ @requires_type_collecting
def test_print_exception_stderr_is_none_1(self):
script = r"""if True:
import sys
# Issue #18960: coding spec should has no effect
do_test("0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
+ @support.requires_type_collecting
def test_print_traceback_at_exit(self):
# Issue #22599: Ensure that it is possible to use the traceback module
# to display an exception at Python exit
class FinalizationTest(unittest.TestCase):
+ @support.requires_type_collecting
def test_finalization(self):
# Issue #19421: warnings.warn() should not crash
# during Python finalization
del c1, c2, C, D
gc.collect()
+ @support.requires_type_collecting
def test_callback_in_cycle_resurrection(self):
import gc