Every time you call fopen, you need to do a null check. Every single time. You also need to check that fclose is there to match the call, every time.
Writing a test for that, when it is generally just a call within the function you want to test, isn't really possible. It's not there in the arguments, or the return value, of the function.
How do you check for the right checks in a function expected to do something like this: