-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
gh-148402: add missing stacklevel to warnings.warn() in subprocess.Popen #148400
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3177,6 +3177,18 @@ def test_pass_fds(self): | |
| close_fds=False, pass_fds=(fd, ))) | ||
| self.assertIn('overriding close_fds', str(context.warning)) | ||
|
|
||
| def test_pass_fds_overriding_close_fds_warning_location(self): | ||
|
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. So this warning was not tested at all? |
||
| # gh-148402: the warning should point to the caller, not subprocess.py | ||
| fd = os.dup(1) | ||
| self.addCleanup(os.close, fd) | ||
| os.set_inheritable(fd, True) | ||
| with self.assertWarns(RuntimeWarning) as context: | ||
| p = subprocess.Popen(ZERO_RETURN_CMD, | ||
| close_fds=False, pass_fds=(fd,)) | ||
| p.wait() | ||
| self.assertIn('overriding close_fds', str(context.warning)) | ||
| self.assertEqual(context.filename, __file__) | ||
|
|
||
| def test_pass_fds_inheritable(self): | ||
| script = support.findfile("fd_status.py", subdir="subprocessdata") | ||
|
|
||
|
|
@@ -3762,8 +3774,7 @@ def test_close_fds_with_stdio(self): | |
| self.assertIn(b"OSError", stderr) | ||
|
|
||
| # Check for a warning due to using handle_list and close_fds=False | ||
| with warnings_helper.check_warnings((".*overriding close_fds", | ||
| RuntimeWarning)): | ||
| with self.assertWarns(RuntimeWarning) as context: | ||
| startupinfo = subprocess.STARTUPINFO() | ||
| startupinfo.lpAttributeList = {"handle_list": handles[:]} | ||
| p = subprocess.Popen([sys.executable, "-c", | ||
|
|
@@ -3772,6 +3783,9 @@ def test_close_fds_with_stdio(self): | |
| startupinfo=startupinfo, close_fds=False) | ||
| stdout, stderr = p.communicate() | ||
| self.assertEqual(p.returncode, 0) | ||
| self.assertIn('overriding close_fds', str(context.warning)) | ||
| # gh-148402: warning should point to the caller, not subprocess.py | ||
| self.assertEqual(context.filename, __file__) | ||
|
|
||
| def test_empty_attribute_list(self): | ||
| startupinfo = subprocess.STARTUPINFO() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add missing ``stacklevel`` to two :func:`warnings.warn` calls in | ||
|
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. This description contains implementation details not interesting to the user. Just describe what was changed from the user's point of view. |
||
| :class:`subprocess.Popen` so that warnings correctly point to the caller's | ||
| code instead of ``subprocess.py`` internals. | ||
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 split the line so it is not exceed 80 columns.