TST: do not remove files while they are open

Fixes WindowsError: [Error 32] The process cannot access the file because it is being used by another process
BUG: do not remove file if passed in file object

Fix WindowsError: [Error 32] The process cannot access the file because it is being used by another process
TST: On Windows open files can not be removed
Merge pull request #3250 from cgohlke/patch-2

Fix WindowsError: [Error 32] The process cannot access the file