Skip to content

Commit 1a0364d

Browse files
author
Anselm Kruis
committed
bpo-30028: Run the fork test as an external script.
1 parent 9ca9665 commit 1a0364d

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Lib/test/test_support.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import socket
88
import tempfile
99
import errno
10+
import textwrap
1011
from test import support
12+
from test.support import script_helper
1113

1214
TESTFN = support.TESTFN
1315

@@ -164,16 +166,18 @@ def test_temp_dir__existing_dir__quiet_true(self):
164166
@unittest.skipUnless(hasattr(os, "fork"), "test requires os.fork")
165167
def test_temp_dir__forked_child(self):
166168
"""Test that a forked child process does not remove the directory."""
167-
with support.temp_cwd() as temp_path:
168-
pid = os.fork()
169-
if pid != 0:
170-
# parent process
171-
os.waitpid(pid, 0) # wait for the child to terminate
172-
# make sure that temp_path is still present
173-
self.assertTrue(os.path.isdir(temp_path))
174-
if pid == 0:
175-
# terminate the child in order to not confuse the test runner
176-
os._exit(0)
169+
# Run the test as an external script, because it uses fork.
170+
script_helper.assert_python_ok("-c", textwrap.dedent("""
171+
import os
172+
from test import support
173+
with support.temp_cwd() as temp_path:
174+
pid = os.fork()
175+
if pid != 0:
176+
# parent process
177+
os.waitpid(pid, 0) # wait for the child to terminate
178+
# make sure that temp_path is still present
179+
assert os.path.isdir(temp_path), "Child removed temp_path."
180+
"""))
177181

178182
# Tests for change_cwd()
179183

0 commit comments

Comments
 (0)