Use my tempdir - exception
examples/advanced/use_my_tempdir_exception.py
import os from my_tempdir import my_tempdir with my_tempdir() as tmp_dir: print(f"In return context with {tmp_dir}") with open(tmp_dir + '/data.txt', 'w') as fh: fh.write("hello") print(os.listdir(tmp_dir)) raise Exception('trouble') print('') print(tmp_dir) print(os.path.exists(tmp_dir))
start return In return context with /tmp/1578211921.12552210.9000097350821897 ['data.txt'] end return Traceback (most recent call last): File "use_my_tempdir_exception.py", line 9, in <module> raise Exception('trouble') Exception: trouble