Recently, Ned Batchelder during his talk at PyCon 2016 noted:
If you are using unittest to write your tests, definitely use addCleanu
unittest
addCleanu
Another good thing about addCleanup is that it just works as you'd expect.
addCleanup
For example, if you call it in a setUp function, then all test methods will call the cleanup function in the end.
setUp
If you call it in a test method, only this method calls the cleanup function.