diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index 34110dbcace7e1..51dc998475c14f 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -212,7 +212,7 @@ check_impl_detail, requires_debug_ranges, gc_collect, Py_GIL_DISABLED) from test.support.script_helper import assert_python_ok -from test.support import threading_helper, import_helper +from test.support import threading_helper, import_helper, refleak_helper from test.support.bytecode_helper import instructions_with_positions from opcode import opmap, opname from _testcapi import code_offset_to_line @@ -667,6 +667,11 @@ def func2(): @cpython_only def test_unusual_constants(self): + # We cannot use the @skipIf here because hunting_for_refleaks() + # is only true once we start executing the test. + if Py_GIL_DISABLED and refleak_helper.hunting_for_refleaks(): + raise unittest.SkipTest("Immortalized objects trigger refleak detection") + # gh-130851: Code objects constructed with constants that are not # types generated by the bytecode compiler should not crash the # interpreter.