-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
base: main
Are you sure you want to change the base?
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.
…_hostname_idn use by test_ssl_in_multiple_threads