File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change 7
7
import socket
8
8
import tempfile
9
9
import errno
10
+ import textwrap
10
11
from test import support
12
+ from test .support import script_helper
11
13
12
14
TESTFN = support .TESTFN
13
15
@@ -164,16 +166,18 @@ def test_temp_dir__existing_dir__quiet_true(self):
164
166
@unittest .skipUnless (hasattr (os , "fork" ), "test requires os.fork" )
165
167
def test_temp_dir__forked_child (self ):
166
168
"""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
+ """ ))
177
181
178
182
# Tests for change_cwd()
179
183
You can’t perform that action at this time.
0 commit comments