Skip to content

Commit 5f5b9f5

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 b78e4a1 commit 5f5b9f5

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
@@ -215,14 +215,15 @@ def test_figureoptions():
215215

216216

217217
@pytest.mark.backend('QtAgg', skip_on_importerror=True)
218-
def test_save_figure_return():
218+
def test_save_figure_return(tmp_path):
219+
os.chdir(tmp_path)
219220
fig, ax = plt.subplots()
220221
ax.imshow([[1]])
221222
prop = "matplotlib.backends.qt_compat.QtWidgets.QFileDialog.getSaveFileName"
222223
with mock.patch(prop, return_value=("foobar.png", None)):
223224
fname = fig.canvas.manager.toolbar.save_figure()
224-
os.remove("foobar.png")
225225
assert fname == "foobar.png"
226+
assert (tmp_path / "foobar.png").exists()
226227
with mock.patch(prop, return_value=(None, None)):
227228
fname = fig.canvas.manager.toolbar.save_figure()
228229
assert fname is None

0 commit comments

Comments
 (0)