MAINT: Fix python3 ResourceWarning when running test_exec_command.py

The tests in test_exec_command.py used with blocks with a context
manager that could redirect stderr and stdout to temporary files but
those files were not closed on exit from the block.