summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sys_settrace.py
diff options
context:
space:
mode:
authorŁukasz Langa <lukasz@langa.pl>2022-07-05 19:02:43 (GMT)
committerGitHub <noreply@github.com>2022-07-05 19:02:43 (GMT)
commit5f4a16b2913ac84ccaab95b50dd4b0e7fbc58ec2 (patch)
treea417ba17d510a1732c23bd41eff752c95ebddb19 /Lib/test/test_sys_settrace.py
parent552fc9a9acd81694bee2001f68ba155315360cfa (diff)
downloadcpython-5f4a16b2913ac84ccaab95b50dd4b0e7fbc58ec2.zip
cpython-5f4a16b2913ac84ccaab95b50dd4b0e7fbc58ec2.tar.gz
cpython-5f4a16b2913ac84ccaab95b50dd4b0e7fbc58ec2.tar.bz2
[3.11] gh-94510: Raise on re-entrant calls to sys.setprofile and sys.settrace (GH-94511) (GH-94578)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 40d81fd63b46cf998880ce3bf3e5cb42bc3199c1)
Diffstat (limited to 'Lib/test/test_sys_settrace.py')
-rw-r--r--Lib/test/test_sys_settrace.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index fd2740e..7ec290d 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -2,6 +2,7 @@
from test import support
import unittest
+from unittest.mock import MagicMock
import sys
import difflib
import gc
@@ -2684,5 +2685,43 @@ class TestExtendedArgs(unittest.TestCase):
self.assertEqual(counts, {'call': 1, 'line': 2000, 'return': 1})
+class TestEdgeCases(unittest.TestCase):
+
+ def setUp(self):
+ self.addCleanup(sys.settrace, sys.gettrace())
+ sys.settrace(None)
+
+ def test_reentrancy(self):
+ def foo(*args):
+ ...
+
+ def bar(*args):
+ ...
+
+ class A:
+ def __call__(self, *args):
+ pass
+
+ def __del__(self):
+ sys.settrace(bar)
+
+ sys.settrace(A())
+ with support.catch_unraisable_exception() as cm:
+ sys.settrace(foo)
+ self.assertEqual(cm.unraisable.object, A.__del__)
+ self.assertIsInstance(cm.unraisable.exc_value, RuntimeError)
+
+ self.assertEqual(sys.gettrace(), foo)
+
+
+ def test_same_object(self):
+ def foo(*args):
+ ...
+
+ sys.settrace(foo)
+ del foo
+ sys.settrace(sys.gettrace())
+
+
if __name__ == "__main__":
unittest.main()