Fix ResourceWarning when running tests on Python 3.  Closes #391