8000 Getting the CleanupTest and cleanup to do rcparam handling, too · matplotlib/matplotlib@7d266fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d266fc

Browse files
committed
Getting the CleanupTest and cleanup to do rcparam handling, too
1 parent 4da0e66 commit 7d266fc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ def failer(*args, **kwargs):
6868
return known_fail_decorator
6969

7070

71-
def _do_cleanup(original_units_registry):
71+
def _do_cleanup(original_units_registry, original_settings):
7272
plt.close('all')
7373
gc.collect()
7474

75+
mpl.rcParams.clear()
76+
mpl.rcParams.update(original_settings)
7577
matplotlib.units.registry.clear()
7678
matplotlib.units.registry.update(original_units_registry)
7779
warnings.resetwarnings() # reset any warning filters set in tests
@@ -81,11 +83,13 @@ class CleanupTest(object):
8183
@classmethod
8284
def setup_class(cls):
8385
cls.original_units_registry = matplotlib.units.registry.copy()
86+
cls.original_settings = mpl.rcParams.copy()
8487
matplotlib.tests.setup()
8588

8689
@classmethod
8790
def teardown_class(cls):
88-
_do_cleanup(cls.original_units_registry)
91+
_do_cleanup(cls.original_units_registry,
92+
cls.original_settings)
8993

9094
def test(self):
9195
self._func()
@@ -107,10 +111,12 @@ def cleanup(func):
107111
@functools.wraps(func)
108112
def wrapped_function(*args, **kwargs):
109113
original_units_registry = matplotlib.units.registry.copy()
114+
original_settings = mpl.rcParams.copy()
110115
try:
111116
func(*args, **kwargs)
112117
finally:
113-
_do_cleanup(original_units_registry)
118+
_do_cleanup(original_units_registry,
119+
original_settings)
114120

115121
return wrapped_function
116122

@@ -135,19 +141,18 @@ def setup_class(cls):
135141
matplotlib.style.use(cls._style)
136142
except:
137143
# Restore original settings before raising errors during the update.
144+
mpl.rcParams.clear()
138145
mpl.rcParams.update(cls._initial_settings)
139146
raise
140147
# Because the setup of a CleanupTest might involve
141148
# modifying a few rcparams, this setup should come
142149
# last prior to running the image test.
143150
CleanupTest.setup_class()
151+
cls.original_settings = cls._initial_settings
144152
cls._func()
145153

146154
@classmethod
147155
def teardown_class(cls):
148-
mpl.rcParams.update(cls._initial_settings)
149-
# Just as the setup of a CleanupTest should come last,
150-
# it would be prudent to make the teardown of CleanupTest last.
151156
CleanupTest.teardown_class()
152157

153158
@staticmethod

0 commit comments

Comments
 (0)
0