Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7eab7d9

Browse files
authored
Merge pull request #6707 from Kojoley/do-not-call-gc-collect-by-default
TST: Call `gc.collect` after each test only if the user asks for it
2 parents f1cb77f + e6def4e commit 7eab7d9

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

lib/matplotlib/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,10 +1577,11 @@ def _init_tests():
15771577

15781578

15791579
def _get_extra_test_plugins():
1580+
from .testing.performgc import PerformGC
15801581
from .testing.noseclasses import KnownFailure
15811582
from nose.plugins import attrib
15821583

1583-
return [KnownFailure, attrib.Plugin]
1584+
return [PerformGC, KnownFailure, attrib.Plugin]
15841585

15851586

15861587
def _get_nose_env():

lib/matplotlib/testing/decorators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def failer(*args, **kwargs):
7272

7373
def _do_cleanup(original_units_registry, original_settings):
7474
plt.close('all')
75-
gc.collect()
7675

7776
mpl.rcParams.clear()
7877
mpl.rcParams.update(original_settings)

lib/matplotlib/testing/performgc.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import gc
5+
import os
6+
from nose.plugins import Plugin
7+
8+
9+
class PerformGC(Plugin):
10+
"""This plugin adds option to call ``gc.collect`` after each test"""
11+
enabled = False
12+
13+
def options(self, parser, env=os.environ):
14+
env_opt = 'PERFORM_GC'
15+
parser.add_option('--perform-gc', action='store_true',
16+
dest='performGC', default=env.get(env_opt, False),
17+
help='Call gc.collect() after each test')
18+
19+
def configure(self, options, conf):
20+
if not self.can_configure:
21+
return
22+
23+
self.enabled = getattr(options, 'performGC', False)
24+
25+
def afterTest(self, test):
26+
gc.collect()

0 commit comments

Comments
 (0)