diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 097ba8f32329..530d693ae186 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1577,10 +1577,11 @@ def _init_tests(): def _get_extra_test_plugins(): + from .testing.performgc import PerformGC from .testing.noseclasses import KnownFailure from nose.plugins import attrib - return [KnownFailure, attrib.Plugin] + return [PerformGC, KnownFailure, attrib.Plugin] def _get_nose_env(): diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index 321fb7e1f88a..a85136bb72f7 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -72,7 +72,6 @@ def failer(*args, **kwargs): def _do_cleanup(original_units_registry, original_settings): plt.close('all') - gc.collect() mpl.rcParams.clear() mpl.rcParams.update(original_settings) diff --git a/lib/matplotlib/testing/performgc.py b/lib/matplotlib/testing/performgc.py new file mode 100644 index 000000000000..818fbd96f44f --- /dev/null +++ b/lib/matplotlib/testing/performgc.py @@ -0,0 +1,26 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import gc +import os +from nose.plugins import Plugin + + +class PerformGC(Plugin): + """This plugin adds option to call ``gc.collect`` after each test""" + enabled = False + + def options(self, parser, env=os.environ): + env_opt = 'PERFORM_GC' + parser.add_option('--perform-gc', action='store_true', + dest='performGC', default=env.get(env_opt, False), + help='Call gc.collect() after each test') + + def configure(self, options, conf): + if not self.can_configure: + return + + self.enabled = getattr(options, 'performGC', False) + + def afterTest(self, test): + gc.collect()