pybamm-team / PyBaMM

Fast and flexible physics-based battery models in Python
https://www.pybamm.org/
BSD 3-Clause "New" or "Revised" License
1.08k stars 533 forks source link

Use `tempfile` for temporary JSON files. #4206

Closed prady0t closed 2 months ago

prady0t commented 3 months ago

After merging #4125 , we generate a lot of temporary JSON files while running tests. These files are short-lived and are created and deleted with every test passing, although if the tests fail these files have to be deleted manually.

You can see the number of json files being generated when test suit fails many times :

Screenshot 2024-06-18 at 6 27 55 PM

We can use tempfile to generate temporary files to fix this. See : https://docs.python.org/3/library/tempfile.html

prady0t commented 3 months ago

You can assign this to me, I will open a PR soon.

kratman commented 3 months ago

This is true for notebooks as well. They make images and other files, but do not clean them up

agriyakhetarpal commented 3 months ago

For the notebooks, I think it's better to not use tempfiles so as to not mislead newcomers to PyBaMM and Python, plus users might want to inspect the images after the notebook/cell has been executed