Skip to content

Commit 7c466f9

Browse files
QuLogictimhoffm
andcommitted
Document the text_placeholders fixture
Co-authored-by: Tim Hoffmann <[email protected]>
1 parent 3e8e9f8 commit 7c466f9

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

doc/devel/testing.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ the tests, they should now pass.
163163

164164
It is preferred that new tests use ``style='mpl20'`` as this leads to smaller
165165
figures and reflects the newer look of default Matplotlib plots. Also, if the
166-
texts (labels, tick labels, etc) are not really part of what is tested, use
167-
``remove_text=True`` as this will lead to smaller figures and reduce possible
168-
issues with font mismatch on different platforms.
166+
texts (labels, tick labels, etc) are not really part of what is tested, use the
167+
``remove_text=True`` argument or add the ``text_placeholders`` fixture as this
168+
will lead to smaller figures and reduce possible issues with font mismatch on
169+
different platforms.
169170

170171

171172
Compare two methods of creating an image

lib/matplotlib/testing/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ def test_imshow_xarray(xr):
129129

130130
@pytest.fixture
131131
def text_placeholders(monkeypatch):
132+
"""
133+
Replace texts with placeholder rectangles.
134+
135+
The rectangle size only depends on the font size and the number of characters. It is
136+
thus insensitive to font properties and rendering details. This should be used for
137+
tests that depend on text geometries but not the actual text rendering, e.g. layout
138+
tests.
139+
"""
132140
from matplotlib.patches import Rectangle
133141

134142
def patched_get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi):

0 commit comments

Comments
 (0)