diff --git a/tests/unit/test_batch_study.py b/tests/unit/test_batch_study.py index 89e6bd62b0..c04e71b5cb 100644 --- a/tests/unit/test_batch_study.py +++ b/tests/unit/test_batch_study.py @@ -93,14 +93,18 @@ def test_create_gif(self): bs = pybamm.BatchStudy({"spm": pybamm.lithium_ion.SPM()}) bs.solve([0, 10]) + # Create a temporary file name + test_stub = "batch_study_test" + test_file = f"{test_stub}.gif" + # create a GIF before calling the plot method - bs.create_gif(number_of_images=3, duration=1) + bs.create_gif(number_of_images=3, duration=1, output_filename=test_file) # create a GIF after calling the plot method bs.plot(testing=True) - bs.create_gif(number_of_images=3, duration=1) + bs.create_gif(number_of_images=3, duration=1, output_filename=test_file) - os.remove("plot.gif") + os.remove(test_file) if __name__ == "__main__": diff --git a/tests/unit/test_plotting/test_quick_plot.py b/tests/unit/test_plotting/test_quick_plot.py index 3415777ee8..418cee8765 100644 --- a/tests/unit/test_plotting/test_quick_plot.py +++ b/tests/unit/test_plotting/test_quick_plot.py @@ -290,11 +290,12 @@ def test_spm_simulation(self): quick_plot.plot(0) # test creating a GIF - quick_plot.create_gif(number_of_images=3, duration=3) - assert not os.path.exists("plot*.png") - assert os.path.exists("plot.gif") - os.remove("plot.gif") - + test_stub = "spm_sim_test" + test_file = f"{test_stub}.gif" + quick_plot.create_gif(number_of_images=3, duration=3, output_filename=test_file) + assert not os.path.exists(f"{test_stub}*.png") + assert os.path.exists(test_file) + os.remove(test_file) pybamm.close_plots() def test_loqs_spme(self): diff --git a/tests/unit/test_simulation.py b/tests/unit/test_simulation.py index d0926e5c94..f008c7ff2a 100644 --- a/tests/unit/test_simulation.py +++ b/tests/unit/test_simulation.py @@ -343,14 +343,18 @@ def test_create_gif(self): sim = pybamm.Simulation(pybamm.lithium_ion.SPM()) sim.solve(t_eval=[0, 10]) + # Create a temporary file name + test_stub = "test_sim" + test_file = f"{test_stub}.gif" + # create a GIF without calling the plot method - sim.create_gif(number_of_images=3, duration=1) + sim.create_gif(number_of_images=3, duration=1, output_filename=test_file) # call the plot method before creating the GIF sim.plot(testing=True) - sim.create_gif(number_of_images=3, duration=1) + sim.create_gif(number_of_images=3, duration=1, output_filename=test_file) - os.remove("plot.gif") + os.remove(test_file) def test_drive_cycle_interpolant(self): model = pybamm.lithium_ion.SPM()