When writing unit tests, I can use unittest.mock
to isolate dependencies and monitor use of the mocked functions. Can I do the same with calls to builtin functions?
In particular, it would be nice to mock open()
so that I can provide test input, or monitor output, without involving disk files. Is this possible, and adviseable? (I already know this can be done, without mocking, for functions that accept an open file object rather than a filename.)