10000 add CleanupTestCase, a unittest.TestCase with cleanup · matplotlib/matplotlib@6cf4d84 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6cf4d84

Browse files
committed
add CleanupTestCase, a unittest.TestCase with cleanup
1 parent de1c8ae commit 6cf4d84

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from matplotlib.testing.compare import comparable_formats, compare_images, \
1919
make_test_filename
2020
import warnings
21+
import unittest
2122

2223
def knownfailureif(fail_condition, msg=None, known_exception_class=None ):
2324
"""
@@ -58,6 +59,7 @@ def failer(*args, **kwargs):
5859
return nose.tools.make_decorator(f)(failer)
5960
return known_fail_decorator
6061

62+
6163
class CleanupTest(object):
6264
@classmethod
6365
def setup_class(cls):
@@ -71,11 +73,30 @@ def teardown_class(cls):
7173

7274
matplotlib.units.registry.clear()
7375
matplotlib.units.registry.update(cls.original_units_registry)
74-
warnings.resetwarnings() #reset any warning filters set in tests
76+
warnings.resetwarnings() # reset any warning filters set in tests
7577

7678
def test(self):
7779
self._func()
7880

81+
82+
class CleanupTestCase(unittest.TestCase):
83+
'''A wrapper for unittest.TestCase that includes cleanup operations'''
84+
@classmethod
85+
def setUpClass(cls):
86+
import matplotlib.units
87+
cls.original_units_registry = matplotlib.units.registry.copy()
88+
89+
@classmethod
90+
def tearDownClass(cls):
91+
plt.close('all')
92+
93+
matplotlib.tests.setup()
94+
95+
matplotlib.units.registry.clear()
96+
matplotlib.units.registry.update(cls.original_units_registry)
97+
warnings.resetwarnings() # reset any warning filters set in tests
98+
99+
79100
def cleanup(func):
80101
name = func.__name__
81102
func = staticmethod(func)

0 commit comments

Comments
 (0)
0