-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-126483: disable warnings filters mutation in concurrent test_check… #132694
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
gh-126483: disable warnings filters mutation in concurrent test_check… #132694
Conversation
…_check_hostname_idn use by test_ssl_in_multiple_threads
Lib/test/test_ssl.py
Outdated
with ( | ||
ThreadedEchoServer(context=server_context, chatty=True) as server, | ||
warnings_helper.check_no_resource_warning(self) | ||
if warnings_filters | ||
else nullcontext(), | ||
self.assertRaises(UnicodeError), | ||
): | ||
context.wrap_socket(socket.socket(), server_hostname='.pythontest.net') | ||
|
||
with ( | ||
ThreadedEchoServer(context=server_context, chatty=True) as server, | ||
warnings_helper.check_no_resource_warning(self) | ||
if warnings_filters | ||
else nullcontext(), | ||
self.assertRaises(UnicodeDecodeError), | ||
): | ||
context.wrap_socket( | ||
socket.socket(), | ||
server_hostname=b'k\xf6nig.idn.pythontest.net', | ||
) |
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.
I suggest the following:
def get_warnings_filter_context(self, warnings_filter):
if warnings_filters:
return warnings_helper.check_no_resource_warning(self)
return nullcontext()
so that it can be used as follows:
with (
ThreadedEchoServer(context=server_context, chatty=True) as server,
self.get_warnings_filter_context(warnings_filters),
self.assertRaises(UnicodeError),
):
context.wrap_socket(socket.socket(), server_hostname='.pythontest.net')
with (
ThreadedEchoServer(context=server_context, chatty=True) as server,
self.get_warnings_filter_context(warnings_filters),
self.assertRaises(UnicodeDecodeError),
):
context.wrap_socket(
socket.socket(),
server_hostname=b'k\xf6nig.idn.pythontest.net',
)
It took me a while to see the ternary if-else
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.
I'll add some extra parenthesis, like ruff would
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.
It's a good alternative. As I'm on mobile I'll let @gpshead do the merge.
Thanks @graingert for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…pythonGH-132694) The `test_ssl_in_multiple_threads` test failed because `test_check_hostname_idn()` modified the global warnings filters via `warnings_helper.check_no_resource_warning()`. Only check for warnings when the context aware warnings feature is enabled, which makes the warnings filter context-local and thread-safe. (cherry picked from commit 40c8be0) Co-authored-by: Thomas Grainger <tagrain@gmail.com>
…pythonGH-132694) The `test_ssl_in_multiple_threads` test failed because `test_check_hostname_idn()` modified the global warnings filters via `warnings_helper.check_no_resource_warning()`. Only check for warnings when the context aware warnings feature is enabled, which makes the warnings filter context-local and thread-safe. (cherry picked from commit 40c8be0) Co-authored-by: Thomas Grainger <tagrain@gmail.com>
GH-135131 is a backport of this pull request to the 3.14 branch. |
GH-135132 is a backport of this pull request to the 3.13 branch. |
GH-132694) (GH-135131) The `test_ssl_in_multiple_threads` test failed because `test_check_hostname_idn()` modified the global warnings filters via `warnings_helper.check_no_resource_warning()`. Only check for warnings when the context aware warnings feature is enabled, which makes the warnings filter context-local and thread-safe. (cherry picked from commit 40c8be0) Co-authored-by: Thomas Grainger <tagrain@gmail.com>
GH-132694) (GH-135132) The `test_ssl_in_multiple_threads` test failed because `test_check_hostname_idn()` modified the global warnings filters via `warnings_helper.check_no_resource_warning()`. Disable the warnings check in the multi-threaded test because `warnings_helper` isn't thread-safe in 3.13 or earlier. (cherry picked from commit 40c8be0) Co-authored-by: Thomas Grainger <tagrain@gmail.com> * Fix for 3.13 --------- Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Sam Gross <colesbury@gmail.com>
…_hostname_idn use by test_ssl_in_multiple_threads