Skip to content

feature request: python version dependent reference images #264

@rsokolewicz

Description

@rsokolewicz

hi! I have a project with a CI/CD pipeline that runs pytest across different python versions, and today ran into a rather annoying issue where the matplotlib images on py3.10 are slightly different from py3.13 (text being offset by a few pixels). Now, if I regenerate the reference images on 3.10, the tests on 3.13 will fail, and the other way around as well.

I was hoping to be able to add python-version dependent reference images. Something like

@pytest.mark.mpl_image_compare(baseline_dir="baselines/{py_version}")
def test_my_plot():
...

which would detect the python version. Then the user (me) could run

pytest --mpl-generate-path=baselines/3.10

and

pytest --mpl-generate-path=baselines/3.13

if i need version dependent reference images.

edit: matplotlib 3.11 introduced a new text renderer that causes the mismatching images. The release notes https://matplotlib.org/stable/release/prev_whats_new/whats_new_3.11.0.html#fonts-and-text highlight a few workarounds. Adding here in case someone stumbles on this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions