Skip to content

Commit ee0bc9d

Browse files
committed
TST: Use a temporary directory for test_save_figure_return
This avoids having to manually clean up the resulting file, which seems flaky.
1 parent fc49cee commit ee0bc9d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,15 @@ def test_figureoptions():
219219

220220

221221
@pytest.mark.backend('QtAgg', skip_on_importerror=True)
222-
def test_save_figure_return():
222+
def test_save_figure_return(tmp_path):
223+
os.chdir(tmp_path)
223224
fig, ax = plt.subplots()
224225
ax.imshow([[1]])
225226
prop = "matplotlib.backends.qt_compat.QtWidgets.QFileDialog.getSaveFileName"
226227
with mock.patch(prop, return_value=("foobar.png", None)):
227228
fname = fig.canvas.manager.toolbar.save_figure()
228-
os.remove("foobar.png")
229229
assert fname == "foobar.png"
230+
assert (tmp_path / "foobar.png").exists()
230231
with mock.patch(prop, return_value=(None, None)):
231232
fname = fig.canvas.manager.toolbar.save_figure()
232233
assert fname is None

0 commit comments

Comments
 (0)