Skip to content

Commit 628a68f

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 553cec1 commit 628a68f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 5 additions & 4 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):
219219
fig, ax = plt.subplots()
220220
ax.imshow([[1]])
221+
expected = tmp_path / "foobar.png"
221222
prop = "matplotlib.backends.qt_compat.QtWidgets.QFileDialog.getSaveFileName"
222-
with mock.patch(prop, return_value=("foobar.png", None)):
223+
with mock.patch(prop, return_value=(str(expected), None)):
223224
fname = fig.canvas.manager.toolbar.save_figure()
224-
os.remove("foobar.png")
225-
assert fname == "foobar.png"
225+
assert fname == str(expected)
226+
assert expected.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)