Skip to content

Commit

Permalink
MRG: TESTS: Fail on ImportWarning (#376)
Browse files Browse the repository at this point in the history
* TESTS: Fail on ImportWarning

* TESTS: Filter import warnings on mne-python <0.20

* Silence numpy warnings early in tests

* Revert "Silence numpy warnings early in tests"

This reverts commit c6390c8.

* Simplify numpy warning filter
  • Loading branch information
hoechenberger authored Mar 28, 2020
1 parent 826a7da commit 8180b18
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 18 deletions.
15 changes: 10 additions & 5 deletions mne_bids/commands/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@
from os import path as op

import pytest
import mne

# This is here to handle mne-python <0.20
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore',
message="can't resolve package",
category=ImportWarning)
import mne

from mne.datasets import testing
from mne.utils import run_tests_if_main, ArgvSetter

from mne_bids.commands import mne_bids_raw_to_bids, mne_bids_cp


base_path = op.join(op.dirname(mne.__file__), 'io')
subject_id = '01'
task = 'testing'

# Silence NumPy warnings
# See https://stackoverflow.com/a/40846742
pytestmark = pytest.mark.filterwarnings('ignore:numpy.ufunc size changed')


def check_usage(module, force_help=False):
"""Ensure we print usage."""
Expand Down
10 changes: 9 additions & 1 deletion mne_bids/tests/test_copyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
import pytest

from scipy.io import savemat
import mne

# This is here to handle mne-python <0.20
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore',
message="can't resolve package",
category=ImportWarning)
import mne

from mne.datasets import testing
from mne.utils import _TempDir
from mne_bids.utils import _handle_kind, _parse_ext
Expand Down
8 changes: 8 additions & 0 deletions mne_bids/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
# License: BSD (3-clause)
import os.path as op

# This is here to handle mne-python <0.20
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore',
message="can't resolve package",
category=ImportWarning)
import mne # noqa: F401

from mne.io import read_raw_brainvision

from mne_bids.datasets import fetch_faces_data, fetch_brainvision_testing_data
Expand Down
8 changes: 8 additions & 0 deletions mne_bids/tests/test_pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

import os.path as op

# This is here to handle mne-python <0.20
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore',
message="can't resolve package",
category=ImportWarning)
import mne # noqa: F401

from mne.datasets import testing
from mne.io import read_raw_fif
from mne_bids.pick import coil_type
Expand Down
13 changes: 8 additions & 5 deletions mne_bids/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
import numpy as np
from numpy.testing import assert_almost_equal

import mne
# This is here to handle mne-python <0.20
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore',
message="can't resolve package",
category=ImportWarning)
import mne

from mne.io import anonymize_info
from mne.utils import _TempDir, requires_nibabel, check_version, object_diff
from mne.datasets import testing, somato
Expand Down Expand Up @@ -49,10 +56,6 @@
somato_raw_fname = op.join(somato_path, 'sub-01', 'meg',
'sub-01_task-somato_meg.fif')

# Silence NumPy warnings
# See https://stackoverflow.com/a/40846742
pytestmark = pytest.mark.filterwarnings('ignore:numpy.ufunc size changed')

warning_str = dict(
channel_unit_changed='ignore:The unit for chann*.:RuntimeWarning:mne',
meas_date_set_to_none="ignore:.*'meas_date' set to None:RuntimeWarning:"
Expand Down
9 changes: 9 additions & 0 deletions mne_bids/tests/test_tsv_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

import os.path as op
from collections import OrderedDict as odict

# This is here to handle mne-python <0.20
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore',
message="can't resolve package",
category=ImportWarning)
import mne # noqa: F401

from mne_bids.tsv_handler import (_from_tsv, _to_tsv, _combine, _drop,
_contains_row, _tsv_to_str)
import pytest
Expand Down
10 changes: 9 additions & 1 deletion mne_bids/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
from pathlib import Path

from numpy.random import random
import mne

# This is here to handle mne-python <0.20
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore',
message="can't resolve package",
category=ImportWarning)
import mne

from mne.utils import _TempDir
from mne.datasets import testing

Expand Down
14 changes: 9 additions & 5 deletions mne_bids/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@

import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
import mne

# This is here to handle mne-python <0.20
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore',
message="can't resolve package",
category=ImportWarning)
import mne

from mne.datasets import testing
from mne.utils import (_TempDir, run_subprocess, check_version,
requires_nibabel, requires_version)
Expand Down Expand Up @@ -53,10 +61,6 @@
task=task)
bids_basename_minimal = make_bids_basename(subject=subject_id, task=task)

# Silence NumPy warnings
# See https://stackoverflow.com/a/40846742
pytestmark = pytest.mark.filterwarnings('ignore:numpy.ufunc size changed')

warning_str = dict(
channel_unit_changed='ignore:The unit for chann*.:RuntimeWarning:mne',
meas_date_set_to_none="ignore:.*'meas_date' set to None:RuntimeWarning:"
Expand Down
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[flake8]
exclude = __init__.py
ignore = W504,I101,I100,I201
per-file-ignores =
mne_bids/commands/tests/test_*.py:E402
mne_bids/tests/test_*.py:E402

[tool:pytest]
addopts =
Expand All @@ -9,7 +12,7 @@ addopts =
filterwarnings =
error
ignore::UserWarning
ignore::ImportWarning
ignore:numpy.ufunc size changed.*:RuntimeWarning

[pydocstyle]
convention = pep257
Expand Down

0 comments on commit 8180b18

Please sign in to comment.