Recently, Ned Batchelder during his talk at PyCon 2016 noted:
If you are using
unittest
to write your tests, definitely useaddCleanup
, it's much better thantearDown
.
Up until now, I've never used addCleanup()
and got used to setUp()
/tearDown()
pair of methods for test "set up" and "tear down" phases.
Why should I switch to addCleanup()
instead of tearDown()
?
It was also recently discussed in the Python unittest with Robert Collins podcast.