Django when to use teardown method

前端 未结 3 2058
-上瘾入骨i
-上瘾入骨i 2021-02-18 13:09

According to the docs:

A TestCase, on the other hand, does not truncate tables and reload initial data at the beginning of a test. Instead, it encloses

3条回答
  •  难免孤独
    2021-02-18 13:29

    I was working on a project that handled some file uploads, and i needed to delete the files that were created by the test and the tearDown method was very useful in that situation.

    import shutil
    
    #....
    #....
    
        def tearDown(self):
            shutil.rmtree(settings.UPLOAD_ROOT)
    

提交回复
热议问题