@@ -68,10 +68,12 @@ def failer(*args, **kwargs):
68
68
return known_fail_decorator
69
69
70
70
71
- def _do_cleanup (original_units_registry ):
71
+ def _do_cleanup (original_units_registry , original_settings ):
72
72
plt .close ('all' )
73
73
gc .collect ()
74
74
75
+ mpl .rcParams .clear ()
76
+ mpl .rcParams .update (original_settings )
75
77
matplotlib .units .registry .clear ()
76
78
matplotlib .units .registry .update (original_units_registry )
77
79
warnings .resetwarnings () # reset any warning filters set in tests
@@ -81,11 +83,13 @@ class CleanupTest(object):
81
83
@classmethod
82
84
def setup_class (cls ):
83
85
cls .original_units_registry = matplotlib .units .registry .copy ()
86
+ cls .original_settings = mpl .rcParams .copy ()
84
87
matplotlib .tests .setup ()
85
88
86
89
@classmethod
87
90
def teardown_class (cls ):
88
- _do_cleanup (cls .original_units_registry )
91
+ _do_cleanup (cls .original_units_registry ,
92
+ cls .original_settings )
89
93
90
94
def test (self ):
91
95
self ._func ()
@@ -107,10 +111,12 @@ def cleanup(func):
107
111
@functools .wraps (func )
108
112
def wrapped_function (* args , ** kwargs ):
109
113
original_units_registry = matplotlib .units .registry .copy ()
114
+ original_settings = mpl .rcParams .copy ()
110
115
try :
111
116
func (* args , ** kwargs )
112
117
finally :
113
- _do_cleanup (original_units_registry )
118
+ _do_cleanup (original_units_registry ,
119
+ original_settings )
114
120
115
121
return wrapped_function
116
122
@@ -135,19 +141,18 @@ def setup_class(cls):
135
141
matplotlib .style .use (cls ._style )
136
142
except :
137
143
# Restore original settings before raising errors during the update.
144
+ mpl .rcParams .clear ()
138
145
mpl .rcParams .update (cls ._initial_settings )
139
146
raise
140
147
# Because the setup of a CleanupTest might involve
141
148
# modifying a few rcparams, this setup should come
142
149
# last prior to running the image test.
143
150
CleanupTest .setup_class ()
151
+ cls .original_settings = cls ._initial_settings
144
152
cls ._func ()
145
153
146
154
@classmethod
147
155
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.
151
156
CleanupTest .teardown_class ()
152
157
153
158
@staticmethod
0 commit comments