diff --git a/mne/conftest.py b/mne/conftest.py index c9c8d1160b5..89a275e362b 100644 --- a/mne/conftest.py +++ b/mne/conftest.py @@ -3,6 +3,8 @@ # # License: BSD (3-clause) +from distutils.version import LooseVersion +import gc import os import os.path as op import shutil @@ -79,6 +81,7 @@ def pytest_configure(config): ignore:The sklearn.*module.*deprecated.*:FutureWarning ignore:.*TraitTuple.*trait.*handler.*deprecated.*:DeprecationWarning ignore:.*rich_compare.*metadata.*deprecated.*:DeprecationWarning + ignore:.*In future, it will be an error for 'np.bool_'.*:DeprecationWarning always:.*get_data.* is deprecated in favor of.*:DeprecationWarning """ # noqa: E501 for warning_line in warning_lines.split('\n'): @@ -91,6 +94,7 @@ def pytest_configure(config): def matplotlib_config(): """Configure matplotlib for viz tests.""" import matplotlib + from matplotlib import cbook # "force" should not really be necessary but should not hurt kwargs = dict() with warnings.catch_warnings(record=True): # ignore warning @@ -110,6 +114,18 @@ def matplotlib_config(): else: ETSConfig.toolkit = 'qt4' + # Make sure that we always reraise exceptions in handlers + orig = cbook.CallbackRegistry + + class CallbackRegistryReraise(orig): + def __init__(self, exception_handler=None): + args = () + if LooseVersion(matplotlib.__version__) >= LooseVersion('2.1'): + args += (exception_handler,) + super(CallbackRegistryReraise, self).__init__(*args) + + cbook.CallbackRegistry = CallbackRegistryReraise + @pytest.fixture() def check_gui_ci(): @@ -201,7 +217,7 @@ def backend_name(request): @pytest.yield_fixture -def renderer(backend_name): +def renderer(backend_name, garbage_collect): """Yield the 3D backends.""" from mne.viz.backends.renderer import _use_test_3d_backend _check_skip_backend(backend_name) @@ -211,6 +227,13 @@ def renderer(backend_name): renderer._close_all() +@pytest.yield_fixture +def garbage_collect(): + """Garbage collect on exit.""" + yield + gc.collect() + + @pytest.fixture(scope="module", params=[ "pyvista", ]) diff --git a/mne/io/nirx/nirx.py b/mne/io/nirx/nirx.py index 3abb986dd7e..f7a8ec123d9 100644 --- a/mne/io/nirx/nirx.py +++ b/mne/io/nirx/nirx.py @@ -78,8 +78,9 @@ def __init__(self, fname, preload=False, verbose=None): # Read number of rows/samples of wavelength data last_sample = -1 - for line in _open(files['wl1']): - last_sample += 1 + with _open(files['wl1']) as fid: + for line in fid: + last_sample += 1 # Read participant information file inf = ConfigParser(allow_no_value=True) diff --git a/mne/viz/tests/test_3d.py b/mne/viz/tests/test_3d.py index 11cfbc4c501..40d51cffd07 100644 --- a/mne/viz/tests/test_3d.py +++ b/mne/viz/tests/test_3d.py @@ -639,7 +639,7 @@ def test_plot_volume_source_estimates_morph(): @requires_pysurfer @requires_mayavi @traits_test -def test_plot_vector_source_estimates(): +def test_plot_vector_source_estimates(garbage_collect): """Test plotting of vector source estimates.""" sample_src = read_source_spaces(src_fname) @@ -721,7 +721,7 @@ def test_brain_colorbar(orientation, diverging, lims): @requires_pysurfer @testing.requires_testing_data @traits_test -def test_mixed_sources_plot_surface(): +def test_mixed_sources_plot_surface(garbage_collect): """Test plot_surface() for mixed source space.""" src = read_source_spaces(fwd_fname2) N = np.sum([s['nuse'] for s in src]) # number of sources diff --git a/mne/viz/utils.py b/mne/viz/utils.py index de23bf0dc8c..5cbf6199384 100644 --- a/mne/viz/utils.py +++ b/mne/viz/utils.py @@ -1974,7 +1974,7 @@ def key_press(self, event): elif self.index >= len(self.cycle): self.index = 0 cmap = self.cycle[self.index] - self.cbar.set_cmap(cmap) + self.cbar.mappable.set_cmap(cmap) self.cbar.draw_all() self.mappable.set_cmap(cmap) self.mappable.set_norm(self.cbar.norm) diff --git a/requirements.txt b/requirements.txt index 413684d8991..21a56e19de4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ numpy scipy matplotlib -mayavi pyqt5!=5.14.1 pyqt5-sip sip @@ -23,11 +22,12 @@ joblib psutil dipy https://api.github.com/repos/numpy/numpydoc/zipball/master +mayavi PySurfer[save_movie] nilearn neo xlrd pydocstyle flake8 -https://github.com/mcmtroffaes/sphinxcontrib-bibtex/zipball/29694f215b39d64a31b845aafd9ff2ae9329494f +https://api.github.com/repos/mcmtroffaes/sphinxcontrib-bibtex/zipball/29694f215b39d64a31b845aafd9ff2ae9329494f pyvista>=0.23.1