Skip to content

Commit 155b19c

Browse files
dstansbymeeseeksmachine
authored andcommitted
Backport PR matplotlib#30497: TST: Use a temporary directory for test_save_figure_return
1 parent 851d6a0 commit 155b19c

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
@@ -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):
223223
fig, ax = plt.subplots()
224224
ax.imshow([[1]])
225+
expected = tmp_path / "foobar.png"
225226
prop = "matplotlib.backends.qt_compat.QtWidgets.QFileDialog.getSaveFileName"
226-
with mock.patch(prop, return_value=("foobar.png", None)):
227+
with mock.patch(prop, return_value=(str(expected), None)):
227228
fname = fig.canvas.manager.toolbar.save_figure()
228-
os.remove("foobar.png")
229-
assert fname == "foobar.png"
229+
assert fname == str(expected)
230+
assert expected.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)