I believe that examining mock would greatly help you with this type of issue. Unit tests are so low level that it's beneficial to get abstract away any function that uses something on the OS (like the file system) and the mock module provides the functionality and framework for creating "fake" constructs (modules, objects, instances) that return pre-determined values allowing you to better test the interface of your design and how your interfaces work together. The proper time to actually test the internal workings of your functions is during CI tests. (Think Travis if you're on Github)