Or you can make it in a nested function in beginning of the test, include `request` in test parameters and put  `request.addfinalizer(cleanup_function_name)` somewhere in the test before critical operations begin.