44import pytest
55from pytest import approx
66
7- from matplotlib .testing .compare import compare_images , make_test_filename
7+ from matplotlib .testing .compare import compare_images
88from matplotlib .testing .decorators import _image_directories
99
1010
4242 # Now test the reverse comparison.
4343 ('all128.png' , 'all127.png' , 0 , 1 ),
4444 ])
45- def test_image_comparison_expect_rms (im1 , im2 , tol , expect_rms ):
45+ def test_image_comparison_expect_rms (im1 , im2 , tol , expect_rms , tmp_path ,
46+ monkeypatch ):
4647 """
4748 Compare two images, expecting a particular RMS error.
4849
@@ -54,16 +55,16 @@ def test_image_comparison_expect_rms(im1, im2, tol, expect_rms):
5455 succeed if compare_images succeeds. Otherwise, the test will succeed if
5556 compare_images fails and returns an RMS error almost equal to this value.
5657 """
58+ # Change the working directory using monkeypatch to use a temporary
59+ # test specific directory
60+ monkeypatch .chdir (tmp_path )
5761 baseline_dir , result_dir = map (Path , _image_directories (lambda : "dummy" ))
58- # Copy both "baseline" and "test" image to result_dir, so that 1)
59- # compare_images writes the diff to result_dir, rather than to the source
60- # tree and 2) the baseline image doesn't appear missing to triage_tests.py.
61- result_im1 = make_test_filename (result_dir / im1 , "expected" )
62- shutil .copyfile (baseline_dir / im1 , result_im1 )
62+ # Copy "test" image to result_dir, so that compare_images writes
63+ # the diff to result_dir, rather than to the source tree
6364 result_im2 = result_dir / im1
6465 shutil .copyfile (baseline_dir / im2 , result_im2 )
6566 results = compare_images (
66- result_im1 , result_im2 , tol = tol , in_decorator = True )
67+ baseline_dir / im1 , result_im2 , tol = tol , in_decorator = True )
6768
6869 if expect_rms is None :
6970 assert results is None
0 commit comments