summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_support.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r--Lib/test/test_support.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index e06f7b8..36d5f84 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -9,9 +9,11 @@ import stat
import subprocess
import sys
import tempfile
+import textwrap
import time
import unittest
from test import support
+from test.support import script_helper
TESTFN = support.TESTFN
@@ -165,6 +167,33 @@ class TestSupport(unittest.TestCase):
f'temporary directory {path!r}: '),
warn)
+ @unittest.skipUnless(hasattr(os, "fork"), "test requires os.fork")
+ def test_temp_dir__forked_child(self):
+ """Test that a forked child process does not remove the directory."""
+ # See bpo-30028 for details.
+ # Run the test as an external script, because it uses fork.
+ script_helper.assert_python_ok("-c", textwrap.dedent("""
+ import os
+ from test import support
+ with support.temp_cwd() as temp_path:
+ pid = os.fork()
+ if pid != 0:
+ # parent process (child has pid == 0)
+
+ # wait for the child to terminate
+ (pid, status) = os.waitpid(pid, 0)
+ if status != 0:
+ raise AssertionError(f"Child process failed with exit "
+ f"status indication 0x{status:x}.")
+
+ # Make sure that temp_path is still present. When the child
+ # process leaves the 'temp_cwd'-context, the __exit__()-
+ # method of the context must not remove the temporary
+ # directory.
+ if not os.path.isdir(temp_path):
+ raise AssertionError("Child removed temp_path.")
+ """))
+
# Tests for change_cwd()
def test_change_cwd(self):