0

I'm currently trying to write a unittest which checks whether or not a function has written an error log. For testing purposes, the error log is to be written to a temporary directory but I am unsure how I can re-route the location of a write() call using unittest.mock.

Any ideas how to go about this?

Chris Nauroth
  • 9,614
  • 1
  • 35
  • 39
Bryan Stafford
  • 301
  • 2
  • 12
  • 1
    Possibly consider monkey patching, as described in this question: https://stackoverflow.com/questions/5626193/what-is-a-monkey-patch . – Chris Nauroth Jul 14 '17 at 17:06
  • Thanks. I refactored my code to include the file paths as instances variables and then reassigned them in the unittest to the temp directory. Problem solved! – Bryan Stafford Jul 14 '17 at 19:56

0 Answers0