Skip to content

Call gc.collect after each test only if the user asks for it #6707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()