Skip to content

Commit

Permalink
Call gc.collect after each test only if the user asks for it
Browse files Browse the repository at this point in the history
  • Loading branch information
Kojoley committed Jul 10, 2016
1 parent 6688af6 commit e6def4e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions lib/matplotlib/testing/performgc.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit e6def4e

Please sign in to comment.