ResourceWarning for a file that is unclosed but UnitTest is throwing it
问题 I have a function like this: def init_cars(self, directory=''): #some_code cars = set([line.rstrip('\n') for line in open(directory + "../myfolder/all_cars.txt")]) #some_more_code I am writing unittest and when I run them, I get the following error: ResourceWarning: unclosed file <_io.TextIOWrapper name='../myfolder/all_cars.txt' mode='r' encoding='UTF-8'> names = set([line.rstrip('\n') for line in open(directory + "../myfolder/all_cars.txt")]) ResourceWarning: Enable tracemalloc to get the