Skip to content

Commit b6263ca

Browse files
authored
[3.6] Test atexit shutdown mechanism in a subprocess (GH-4828) (#4829)
* Test atexit shutdown mechanism in a subprocess. (cherry picked from commit fc5db95)
1 parent b0358e8 commit b6263ca

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lib/test/test_atexit.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io
44
import atexit
55
from test import support
6+
from test.support import script_helper
67

78
### helpers
89
def h1():
@@ -152,6 +153,21 @@ def test_bound_methods(self):
152153
atexit._run_exitfuncs()
153154
self.assertEqual(l, [5])
154155

156+
def test_shutdown(self):
157+
# Actually test the shutdown mechanism in a subprocess
158+
code = """if 1:
159+
import atexit
160+
161+
def f(msg):
162+
print(msg)
163+
164+
atexit.register(f, "one")
165+
atexit.register(f, "two")
166+
"""
167+
res = script_helper.assert_python_ok("-c", code)
168+
self.assertEqual(res.out.decode().splitlines(), ["two", "one"])
169+
self.assertFalse(res.err)
170+
155171

156172
@support.cpython_only
157173
class SubinterpreterTest(unittest.TestCase):

0 commit comments

Comments
 (0)