[issue26612] test_ssl: use context manager (with) to fix ResourceWarning

STINNER Victor report at bugs.python.org
Wed Mar 23 04:02:05 EDT 2016


STINNER Victor added the comment:

Martin Panter added the comment:
> Wouldn’t it be better to fix the underlying problem with the test cases?

I don't feel able to fix AIX issues, and I don't think that we can fix
all issues. You still get ResourceWarning if you interrupt the test
with CTRL+c which is not a bug.

> Also, you can often use self.addCleanup(s.close), which saves a level of indentation (and associated noise in the annotate history).

It may work on some cases, but not all of them. And I like controlling
when a socket is closed: I prefer to close it inside the test, and not
sometime later with unittest magic features.

> Also remember that sockets don’t do context management in Python 2, so this would bring more incompatibilies when merging tests between the two branches.

Since this issue is not really a blocker bug, I suggest to only modify
Python 3.6.

It's a follow-up of all work on ResourceWarning (on Python 3.6) last days:
https://docs.python.org/dev/whatsnew/3.6.html#warnings

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26612>
_______________________________________


More information about the Python-bugs-list mailing list