def test_workdir(): fn = "test_work_dir" os.makedirs(fn) try: assert fn not in os.getcwd() with working_dir(fn): assert fn in os.getcwd() assert fn not in os.getcwd() finally: if os.path.isdir(fn): os.rmdir(fn)