10000 TST: better workaround for NamedTempfile problem on windows · matplotlib/matplotlib@1d1660f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d1660f

Browse files
committed
TST: better workaround for NamedTempfile problem on windows
from #5278 (comment)
1 parent ec6330b commit 1d1660f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/matplotlib/tests/test_font_manager.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ def test_font_priority():
3131
def test_json_serialization():
3232
# on windows, we can't open a file twice, so save the name and unlink
3333
# manually...
34-
with tempfile.NamedTemporaryFile(delete=False) as temp:
35-
name = temp.name
36-
json_dump(fontManager, name)
37-
copy = json_load(name)
38-
os.remove(name)
34+
try:
35+
name = None
36+
with tempfile.NamedTemporaryFile(delete=False) as temp:
37+
name = temp.name
38+
json_dump(fontManager, name)
39+
copy = json_load(name)
40+
finally:
41+
if name and os.path.exists(name):
42+
os.remove(name)
3943
with warnings.catch_warnings():
4044
warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
4145
for prop in ({'family': 'STIXGeneral'},

0 commit comments

Comments
 (0)
0