[SciPy-Dev] Possibly warnings creating errors in development test runs

Sebastian Berg sebastian at sipsolutions.net
Tue Jun 27 06:54:36 EDT 2017


Hi all,

we just merged a PR [1], which (re)enables having warnings cause errors
during testing (only in development mode of course).

Since warnings (especially warnings such as about NaNs) can be system
dependent, it is not unlikely that you may experience new errors during
testing. These are easy to get rid of:

For NaN warnings, you usually should add the numpy errstate context
such as:
```
with np.errstate(invalid="ignore")
```

For most other warnings, add the now new `suppress_warnings` context
manager (please do not use "ignore" warning filters, they can create
issues), such as:
```
from scipy._lib._numpy_compat import suppress_warnings

def test():
    with suppress_warnings() as sup:
        sup.filter(UserWarning, "\nThe coefficients of the spline")
```

The `suppress_warnings` context also supports use as a decorator in
case there are mass of similar suppressions needed in some file.
You can also use `r = sup.record(...)` and check `len(r) == 1` or an
`assert_warns` context if it would be good to test that the warning
occurs.

I hope this does not cause a lot of troubles, probably it is only a few
occurrences, if any, but the new context may be good to know about in
any case.

Regards,

Sebastian


[1] https://github.com/scipy/scipy/pull/7525
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20170627/165a700a/attachment-0001.sig>


More information about the SciPy-Dev mailing list