-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
conftest.py
36 lines (28 loc) · 948 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gc
import pytest
@pytest.fixture
def mpl_cleanup():
"""
Ensure Matplotlib is cleaned up around a test.
Before a test is run:
1) Set the backend to "template" to avoid requiring a GUI.
After a test is run:
1) Reset units registry
2) Reset rc_context
3) Close all figures
See matplotlib/testing/decorators.py#L24.
"""
mpl = pytest.importorskip("matplotlib")
mpl_units = pytest.importorskip("matplotlib.units")
plt = pytest.importorskip("matplotlib.pyplot")
orig_units_registry = mpl_units.registry.copy()
try:
with mpl.rc_context():
mpl.use("template")
yield
finally:
mpl_units.registry.clear()
mpl_units.registry.update(orig_units_registry)
plt.close("all")
# https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.6.0.html#garbage-collection-is-no-longer-run-on-figure-close
gc.collect(1)