Skip to content

TEST: Suppress expected warnings #949

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 21 commits into from
Sep 10, 2020
Merged

Conversation

effigies
Copy link
Member

Tests are currently generating a huge number of warnings, which makes outputs less informative than they could be.

Will add subdirectories soon, but want to get CI going to make sure I'm not breaking things.

@codecov
Copy link

codecov bot commented Aug 22, 2020

Codecov Report

Merging #949 into master will increase coverage by 0.02%.
The diff coverage is 97.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #949      +/-   ##
==========================================
+ Coverage   91.84%   91.87%   +0.02%     
==========================================
  Files          97       98       +1     
  Lines       12428    12451      +23     
  Branches     2191     2193       +2     
==========================================
+ Hits        11415    11439      +24     
  Misses        678      678              
+ Partials      335      334       -1     
Impacted Files Coverage Δ
nibabel/cifti2/cifti2.py 96.69% <ø> (ø)
nibabel/testing/__init__.py 99.05% <85.71%> (-0.95%) ⬇️
nibabel/casting.py 86.32% <100.00%> (+0.17%) ⬆️
nibabel/conftest.py 100.00% <100.00%> (ø)
nibabel/deprecator.py 100.00% <100.00%> (ø)
nibabel/keywordonly.py 100.00% <100.00%> (ø)
nibabel/loadsave.py 92.59% <100.00%> (ø)
nibabel/nicom/ascconv.py 89.87% <100.00%> (ø)
nibabel/nicom/dicomreaders.py 58.76% <100.00%> (ø)
nibabel/processing.py 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e65b865...1dc4e8d. Read the comment docs.

@effigies
Copy link
Member Author

Down to a much more reasonable warnings list:

=============================== warnings summary ===============================
/home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/deprecated.py:35
  /home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/deprecated.py:35: DeprecationWarning: The trackvis interface has been deprecated and will be removed in v4.0; please use the 'nibabel.streamlines' interface.
    mod = __import__(self._module_name, fromlist=[''])
/home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/py/_path/local.py:704
  /home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/py/_path/local.py:704: DeprecationWarning: We will remove this module from nibabel 5.0. Please use the built-in Python `*` argument to ensure keyword-only parameters (see PEP 3102).
    __import__(modname)
/home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/py/_path/local.py:704
  /home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/py/_path/local.py:704: FutureWarning: We no longer carry a copy of the 'py3k' module in nibabel; Please import from the 'numpy.compat.py3k' module directly. Full removal scheduled for nibabel 4.0.
    __import__(modname)
/home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/py/_path/local.py:704
  /home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/py/_path/local.py:704: UserWarning: The DICOM readers are highly experimental, unstable, and only work for Siemens time-series at the moment
  Please use with caution.  We would be grateful for your help in improving them
    __import__(modname)
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/externals/tests/test_netcdf.py::test_itemset_no_segfault_on_readonly
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_proxy_api.py::TestMinc1API::test_array_interface_with_dtype
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_proxy_api.py::TestMinc1API::test_asarray
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_proxy_api.py::TestMinc1API::test_fileobj_isolated
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_proxy_api.py::TestMinc1API::test_header_isolated
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_proxy_api.py::TestMinc1API::test_is_proxy
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_proxy_api.py::TestMinc1API::test_ndim
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_proxy_api.py::TestMinc1API::test_proxy_slicing
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_proxy_api.py::TestMinc1API::test_shape
  /home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/externals/netcdf.py:326: RuntimeWarning: Cannot close a netcdf_file opened with mmap=True, when netcdf_variables or arrays referring to its data still exist. All data arrays obtained from such files refer directly to data on disk, and must be copied before the file can be cleanly closed. (See netcdf_file docstring for more information on mmap.)
    ), category=RuntimeWarning)
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/freesurfer/tests/test_mghformat.py: 12 warnings
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_analyze.py: 17 warnings
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_minc1.py: 12 warnings
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_nifti1.py: 35 warnings
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_nifti2.py: 68 warnings
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_spatialimages.py: 4 warnings
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_spm2analyze.py: 20 warnings
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_spm99analyze.py: 15 warnings
  /home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_spatialimages.py:525: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
    np.random.choice(slice_elems, n_elems).tolist())
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/streamlines/tests/test_tractogram.py::TestTractogram::test_creating_invalid_tractogram
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/streamlines/tests/test_tractogram.py::TestTractogram::test_tractogram_creation
  /home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/numpy/core/_asarray.py:86: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
    return array(a, dtype, copy=False, order=order)
venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_filehandles.py::test_multiload
  /home/travis/build/nipy/nibabel/venv/lib/python3.6/site-packages/nibabel-3.1.1+86.g2fc0b52-py3.6.egg/nibabel/tests/test_filehandles.py:29: UserWarning: It would take too long to test file handles, aborting
    warn('It would take too long to test file handles, aborting')

Filtering on-import warnings feels like more work than it's worth. Handling the NetCDF case would need its own PR. Looks like a couple warnings that actually need dealing with for upcoming Numpy...

Copy link
Member Author

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes for a potential reviewer...

@@ -205,7 +205,7 @@ def parse_ascconv(ascconv_str, str_delim='"'):
attrs, content = ASCCONV_RE.match(ascconv_str).groups()
attrs = OrderedDict((tuple(x.split('=')) for x in attrs.split()))
# Normalize string start / end markers to something Python understands
content = content.replace(str_delim, '"""')
content = content.replace(str_delim, '"""').replace("\\", "\\\\")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems like a reasonable fix, but it should get @matthew-brett's or @moloney's eyes to be sure. Previously the line:

tSequenceFileName                        = ""%SiemensSeq%\ep2d_diff""

Resulted in ast.parse() emitting:

nibabel/nicom/tests/test_ascconv.py::test_ascconv_parse
  <unknown>:2: DeprecationWarning: invalid escape sequence \e

@effigies
Copy link
Member Author

effigies commented Sep 1, 2020

@anibalsolon @djarecka @orduek @robbisg Could I trouble one of you for a review?

@effigies effigies force-pushed the test/reduce_warnings branch from 3ca4ece to 786cf99 Compare September 2, 2020 13:28
@djarecka
Copy link
Collaborator

djarecka commented Sep 2, 2020

@effigies - I can take a look, but I was never working on removing the warnings, so don't have experience with it. One question I have after quickly checking pytest website - have you tried --disable-warnings? Or it's not what you want?

@effigies
Copy link
Member Author

effigies commented Sep 2, 2020

No, I want warnings to show if they're valid, as that's one of the better ways to see upcoming deprecations in Python or numpy. But expected warnings that we produce shouldn't clutter the outputs.

@robbisg
Copy link
Collaborator

robbisg commented Sep 2, 2020

I can help, but as @djarecka, I never worked with suppressing warnings. ;)

@djarecka
Copy link
Collaborator

djarecka commented Sep 2, 2020

@effigies - ok, so you're concerned about your own warnings and you want to test them and remove from the output at the sam time. got it!

@@ -345,11 +345,14 @@ def test_deprecated_fields():

# mrparams is the only deprecated field at the moment
# Accessing hdr_data is equivalent to accessing hdr, so double all checks
assert_array_equal(hdr['mrparams'], 0)
with pytest.deprecated_call():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi. if you want to check specific warning, you can also use with pytest.deprecated_call(match="deprecated from version: 2.3")

assert issubclass(w[0].category, ExtensionWarning)
assert "extension" in str(w[0].message)
assert len(w) == 1
assert "extension" in str(w[0].message)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could also use with pytest.warns(ExtensionWarning, match="extension")

@djarecka
Copy link
Collaborator

djarecka commented Sep 4, 2020

@effigies -lgtm, i don't remember why we didn't move from clear_and_catch_warnings. I thought we had some reasons, but perhaps not very important ones.
I recently discovered match in pytest.raises etc., and I really like it, so showed you some examples for future.

@effigies
Copy link
Member Author

effigies commented Sep 5, 2020

i don't remember why we didn't move from clear_and_catch_warnings.

I don't think I realized that pytest was breaking its behavior, and it seemed like an extra task to insert after getting tests working.

Thanks for the suggestions. I think I'll go and look for all the warnings and improve them...

@effigies
Copy link
Member Author

effigies commented Sep 6, 2020

Updated. Would appreciate another look through when you get a chance.

Co-authored-by: Dorota Jarecka <djarecka@gmail.com>
@effigies
Copy link
Member Author

All green. Good to merge?

@djarecka
Copy link
Collaborator

djarecka commented Sep 10, 2020

@effigies - I've just opened diff quickly, and wonder if there is any specific reason why you use unittest for skipping tests (e.g.unittest.skipIf) instead of pytest.mark.skipif ?
haven't noticed this before

@effigies
Copy link
Member Author

Yes. When there's a standard library equivalent, I'm preferring that, on the grounds that one day we may need to migrate from pytest as we did from nose. The more things that are vanilla Python, the less work that should be.

@djarecka
Copy link
Collaborator

ok, i'm still hoping that we don't have to move from pytest anytime soon :-)
lgtm

@effigies
Copy link
Member Author

Nose lasted 10 years, so if pytest does as well, we still have plenty of time.

@effigies effigies merged commit acd69ea into nipy:master Sep 10, 2020
@effigies
Copy link
Member Author

Thanks for reviewing!

@effigies effigies deleted the test/reduce_warnings branch October 16, 2020 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants