1

I have a directory with a bunch of modules. Each module has a bunch of specific tests.

I know how to teardown after methods, classes and modules. What am trying to do is teardown after all the tests in all the modules in the directory are done running.

My directory structure looks something like this:

enter image description here

I created this fixture in the conftest.py:

@pytest.yield_fixture(scope="package")
def **clean_cookie_file**():
  Path.unlink(filename)

Implementation of the fixture looks like this:

@pytest.mark.usefixtures("class_fixture", "**clean_cookie_file**")
class foo(unittest.TestCase):

Expected Result: file deleted

Actual Result: file not deleted

Any help will be much appreciated.

3
  • Have you tried to make your test classes inherit from a base class with the generic teardown? Apr 27, 2020 at 5:41
  • Thank João. My test classes do indeed inherit from the base class. So if I add the tear down logic in the base class, where do I call it from considering that I want to make one teardown call at the end all the tests across all modules.
    – Aziz
    Apr 27, 2020 at 16:02
  • See stackoverflow.com/a/52873379
    – bmshort
    Jun 20, 2020 at 21:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.