bpo-43439: Add audit hooks for gc functions (GH-24794)
diff --git a/Lib/test/audit-tests.py b/Lib/test/audit-tests.py
index ee6fc93..8e66594 100644
--- a/Lib/test/audit-tests.py
+++ b/Lib/test/audit-tests.py
@@ -323,6 +323,24 @@ def hook(event, args):
sock.close()
+def test_gc():
+ import gc
+
+ def hook(event, args):
+ if event.startswith("gc."):
+ print(event, *args)
+
+ sys.addaudithook(hook)
+
+ gc.get_objects(generation=1)
+
+ x = object()
+ y = [x]
+
+ gc.get_referrers(x)
+ gc.get_referents(y)
+
+
if __name__ == "__main__":
from test.support import suppress_msvcrt_asserts