unittest.mock helps a lot to test such corner case: mock initfp() with a MemoryError side effect, maybe also close () to check that the method was called... The new problem is that on 3 instructions, 2 are mocked... The test now checks the test itself or the real application?
Victor