This line is needed on windows--otherwise a handle to test.fits is kept open by the memmap to the data.  Perhaps using memmap=False might also be clearer.