From b28e4c14c8c0f3eb08e9818bc370fa2e09d56b60 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 24 Jun 2022 16:18:41 -0400 Subject: [PATCH 1/2] FIX: make sure addFont test removes the test font --- lib/matplotlib/tests/test_font_manager.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index ef8b467f1709..1d1eef6b8024 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -180,7 +180,16 @@ def test_addfont_as_path(): """Smoke test that addfont() accepts pathlib.Path.""" font_test_file = 'mpltest.ttf' path = Path(__file__).parent / font_test_file - fontManager.addfont(path) + try: + fontManager.addfont(path) + added, = [font for font in fontManager.ttflist + if font.fname.endswith('mpltest.ttf')] + fontManager.ttflist.remove(added) + finally: + to_remove = [font for font in fontManager.ttflist + if font.fname.endswith('mpltest.ttf')] + for font in to_remove: + fontManager.ttflist.remove(font) @pytest.mark.skipif(sys.platform != 'win32', reason='Windows only') From 6b901fecd7f311be29d45cde648bdba590a7ff69 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 24 Jun 2022 16:52:19 -0400 Subject: [PATCH 2/2] MNT: use existing variable for font name rather than hard-coding Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/tests/test_font_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index 1d1eef6b8024..2a34122d48e1 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -183,11 +183,11 @@ def test_addfont_as_path(): try: fontManager.addfont(path) added, = [font for font in fontManager.ttflist - if font.fname.endswith('mpltest.ttf')] + if font.fname.endswith(font_test_file)] fontManager.ttflist.remove(added) finally: to_remove = [font for font in fontManager.ttflist - if font.fname.endswith('mpltest.ttf')] + if font.fname.endswith(font_test_file)] for font in to_remove: fontManager.ttflist.remove(font)