Skip to content

[MNT]: testing.compare.convert can use stale files #32675

In review

Description

@iccir

Summary

I have two local branches:

  • main (after the resvg commit)
  • pre-resvg (before the resvg commit)

If do the following:

  1. Perform a clean checkout of pre-resvg
  2. Run pytest "lib/matplotlib/tests/test_lines.py::test_line_dashes[svg]"
  3. Switch to main
  4. Run pytest again

The result is an ImageComparisonFailure exception:

E           matplotlib.testing.exceptions.ImageComparisonFailure: images not close (RMS 1.746):
E           	result_images/test_lines/line_dashes_svg.png
E           	result_images/test_lines/line_dashes-expected_svg.png
E           	result_images/test_lines/line_dashes_svg-failed-diff.png

The root issue is in convert():

    # Only convert the file if the destination doesn't already exist or
    # is out of date.
    if not newpath.exists() or newpath.stat().st_mtime < path.stat().st_mtime:
        …

"result_images/test_lines/line_dashes-expected_svg.png" was rendered using Inkscape. Since the file already exists and the modification time of the original hasn't changed, it is not re-rendered using resvg. This same issue will also occur if resvg is updated and produces a slightly different image.

We need to not use the existing image if it was created with a different renderer or version. There are plenty of ways to fix this, but I'm not sure which is the best way.

Proposed fix

To be discussed

Activity

  1. jklymak commented on Nov 27, 2026

    @jklymak
    Member

    If the compare fails, could it rebuild the expected png just in case compare again and fail the second time ?

  2. jklymak commented on Nov 27, 2026

    @jklymak
    Member

    Or we could inject metadata using Pillow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions