Visitar URL original
bpo-30028: make test.support.temp_cwd() fork-safe by akruis · Pull Request #1066 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-30028: improve the test case
- better comments
- make sure, that the child exits successfully
  • Loading branch information
Anselm Kruis
Anselm Kruis committed Apr 22, 2017
commit 8cebac881d4689f2f7ed8e2dfda823298d8da4f9
16 changes: 13 additions & 3 deletions Lib/test/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,26 @@ 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."""

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Author

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.

# 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
os.waitpid(pid, 0) # wait for the child to terminate
# make sure that temp_path is still present
# 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.")
"""))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the comment above enough?

Expand Down