addCleanup vs tearDown

前端 未结 3 1527
有刺的猬
有刺的猬 2021-02-03 19:47

Recently, Ned Batchelder during his talk at PyCon 2016 noted:

If you are using unittest to write your tests, definitely use addCleanu

3条回答
  •  孤独总比滥情好
    2021-02-03 20:11

    Another good thing about addCleanup is that it just works as you'd expect.

    For example, if you call it in a setUp function, then all test methods will call the cleanup function in the end.

    If you call it in a test method, only this method calls the cleanup function.

提交回复
热议问题