-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
bpo-30028: make test.support.temp_cwd() fork-safe #1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
22e032a
7b96cf7
9ca9665
1a0364d
0f480d9
8cebac8
1b78826
ee34a5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,9 @@ | |
| import socket | ||
| import tempfile | ||
| import errno | ||
| import textwrap | ||
| from test import support | ||
| from test.support import script_helper | ||
|
|
||
| TESTFN = support.TESTFN | ||
|
|
||
|
|
@@ -164,16 +166,18 @@ def test_temp_dir__existing_dir__quiet_true(self): | |
| @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.""" | ||
| with support.temp_cwd() as temp_path: | ||
| pid = os.fork() | ||
| if pid != 0: | ||
| # parent process | ||
| os.waitpid(pid, 0) # wait for the child to terminate | ||
| # make sure that temp_path is still present | ||
| self.assertTrue(os.path.isdir(temp_path)) | ||
| if pid == 0: | ||
| # terminate the child in order to not confuse the test runner | ||
| os._exit(0) | ||
| # 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 | ||
| os.waitpid(pid, 0) # wait for the child to terminate | ||
|
||
| # make sure that temp_path is still present | ||
| assert os.path.isdir(temp_path), "Child removed temp_path." | ||
|
||
| """)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment explaining that the child exits without removing the temporary directory.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the comment above enough? |
||
|
|
||
| # Tests for change_cwd() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a reference to the issue: bpo-30028
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No other doc string in this file contains a reference to bpo. Therefore I added the reference as a comment.