I am trying to close a file that I read with pandas data frame in the form of
df = pd.read_csv(file_name)
and not example_file = open(file_name)
(there are some solutions with this case)
so I am trying to close the file after reading it or even writing to it. I am aware that python automatically closes back the file but while running unit tests, it throws resource allocation warnings, so in order to get rid of those warnings I need to have the files closed.
I have tried using storing the file name for example
file_name = "randomfile.csv"
and then tried doing
file_name.close()
but this does not work. I have also tried using
df.close()
but that does not work as well.
The original problem is:
ResourceWarning: Enable tracemalloc to get the object allocation traceback
which I found out meant that I have a file opened. And this warning only shows when unit testing.