0

I have created several tests which create different files and folders in the test folder. I want to delete all the folders that have been created through the tests, but only at the end of the test execution. I have written this fixture:

import shutil

@fixture(scope='session',autouse=True)
def delete_files():
    yield None
    shutil.rmtree('test-folder')

But somehow this does not execute last, after all the tests have passed. How to solve this and to delete all the test folders at the end of test execution?

Ian Kurtis
  • 137
  • 7
  • Does this answer your question? [How do I correctly setup and teardown for my pytest class with tests?](https://stackoverflow.com/questions/26405380/how-do-i-correctly-setup-and-teardown-for-my-pytest-class-with-tests) – CallMeStag Sep 21 '21 at 10:40

1 Answers1

2

For another approach, I have made use of the tmp_path directory before, see here for an example use case and here for the docs of that fixture.

CallMeStag
  • 5,467
  • 1
  • 7
  • 22