matplotlib / matplotlib/pytest-mpl
feature request: python version dependent reference images
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 272
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the mpl_image_compare decorator and the --mpl-generate-path option mentioned in the issue. Determine how baseline paths are currently resolved, then define how Python-version-specific paths should be selected and generated; done means separate baselines such as baselines/3.10 and baselines/3.13 can be used without cross-version comparison failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100