summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_atexit.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_atexit.py')
-rw-r--r--Lib/test/test_atexit.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py
index aa56388..3105f6c 100644
--- a/Lib/test/test_atexit.py
+++ b/Lib/test/test_atexit.py
@@ -2,6 +2,7 @@ import sys
import unittest
import io
import atexit
+import os
from test import support
from test.support import script_helper
@@ -203,6 +204,24 @@ class SubinterpreterTest(unittest.TestCase):
self.assertEqual(ret, 0)
self.assertEqual(atexit._ncallbacks(), n)
+ def test_callback_on_subinterpreter_teardown(self):
+ # This tests if a callback is called on
+ # subinterpreter teardown.
+ expected = b"The test has passed!"
+ r, w = os.pipe()
+
+ code = r"""if 1:
+ import os
+ import atexit
+ def callback():
+ os.write({:d}, b"The test has passed!")
+ atexit.register(callback)
+ """.format(w)
+ ret = support.run_in_subinterp(code)
+ os.close(w)
+ self.assertEqual(os.read(r, len(expected)), expected)
+ os.close(r)
+
if __name__ == "__main__":
unittest.main()