Fix most ResourceWarning in the test suite
https://docs.python.org/dev/whatsnew/3.2.html python3 warns about not unclosed files and sockets.
Use context managers with files to close them.
Use context manager to close socket to supervisor on python 3. On python 2 these sockets remain not closed as before.
There are a few warnings left, but output starts to be readable again.