import os import shutil from contextlib import chdir def test_long_path(): # NAME_MAX of 255 long_filename = "_".join(["testdir"]*32) long_path_end = startingwd = os.getcwd() try: # I thought this would have to be 16, i.e. a path length over 4096, PATH_MAX # but seemingly just crossing 1050 is enough to fail for _ in range(4): os.mkdir(long_filename) os.chdir(long_filename) long_path_end = os.path.join(long_path_end, long_filename) os.mkdir(long_filename) long_path_end = os.path.join(long_path_end, long_filename) with chdir(long_filename): #self.assertEqual(os.getcwd(), long_path_end) assert os.getcwd() == long_path_end print("passed") finally: shutil.rmtree(os.path.join(startingwd, long_filename), ignore_errors=True) test_long_path()