I use the following code to read a file in a list
list = [line.rstrip('\n') for line in open(file)]
I have not closed the file manually, because I assume that Python does this with the garbage collector itself.
When I do testing (framework 'unittest') it warns me that the file is unclosed.
ResourceWarning: unclosed file <_io.TextIOWrapper name='test_resources/names.txt' mode='r' encoding='UTF-8'> return [line.rstrip('\n') for line in open(file)]
How do I close the file in a one-liner?