astropy: DeprecationWarning for inspect.getargspec() raises Error/Fail in pytest-3.6

Running the tests for 2.0rc1 I am seeing 24 failures reported, all apparently based on the same

        warnings.warn("inspect.getargspec() is deprecated, "
                      "use inspect.signature() or inspect.getfullargspec()",
>                     DeprecationWarning, stacklevel=2)
E       DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()

../../../../../inspect.py:1041: DeprecationWarning

Setup:

platform darwin -- Python 3.6.1, pytest-3.0.5, py-1.4.32, pluggy-0.4.0

Running tests with Astropy version 2.0rc1.
Running tests in /sw/lib/python3.6/site-packages/astropy.

Date: 2017-06-29T01:55:41

Platform: Darwin-16.6.0-x86_64-i386-64bit

Executable: /sw/bin/python3.6

Full Python Version: 
3.6.1 (default, May  3 2017, 21:41:23) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Numpy: 1.12.1
Scipy: 0.19.1
Matplotlib: 2.0.2
h5py: 2.7.0
Pandas: 0.20.2
Cython: 0.25.2
Using Astropy options: remote_data: none.

rootdir: /sw/lib/python3.6/site-packages/astropy, inifile: 
plugins: hypothesis-3.6.1, backports.unittest-mock-1.2.1

with beautifulsoup 4.6.0.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

Just found it, too - yes, just requires a copy of @mdboom’s fix for the 3.5 version.

Whatever is easier - this is my patch:

diff --git a/astropy/tests/helper.py b/astropy/tests/helper.py
index eeee8e9dc..a87f68fd7 100644
--- a/astropy/tests/helper.py
+++ b/astropy/tests/helper.py
@@ -150,7 +150,13 @@ _warnings_to_ignore_by_pyver = {
         # This can be removed when fixed in py.test.
         # See https://github.com/pytest-dev/pytest/pull/1009
         r"inspect\.getargspec\(\) is deprecated, use "
-        r"inspect\.signature\(\) instead"])}
+        r"inspect\.signature\(\) instead"]),
+    (3, 6): set([
+        # py.test raises this slightly different warning on Python 3.6.
+        # This can be removed when fixed in py.test.
+        # See also https://github.com/pytest-dev/pytest/pull/1009
+        r"inspect\.getargspec\(\) is deprecated, use "
+        r"inspect\.signature\(\) or inspect\.getfullargspec\(\)"])}
 
 

Oh, good that you say that, I haven’t noticed. The base for every PR should be master, we’ll do the backporting separately. However I can change the base on your PR.

Hmm, looks like it has something to do with the warnings.filters setting, because confusingly I saw neither an exception nor a warning when trying

from inspect import getargspec as inspect_getargspec

directly from the python3.6 interpreter. These are the filter settings when starting a new Python 3.6 sessions:

>>> import warnings
>>> warnings.filters
[('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'BytesWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)]
>>> import astropy
>>> warnings.filters
[('ignore', re.compile('numpy.ndarray size changed', re.IGNORECASE), <class 'Warning'>, re.compile(''), 0), ('ignore', re.compile('numpy.ufunc size changed', re.IGNORECASE), <class 'Warning'>, re.compile(''), 0), ('ignore', re.compile('numpy.dtype size changed', re.IGNORECASE), <class 'Warning'>, re.compile(''), 0), ('always', None, <class 'numpy.lib.polynomial.RankWarning'>, None, 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'BytesWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0), ('ignore', re.compile('', re.IGNORECASE), <class 'pkg_resources.PEP440Warning'>, re.compile(''), 0)]

and after running the io.ascii tests (with the failures):

>>> warnings.filters
[('ignore', re.compile('inspect\\.getargspec\\(\\) is deprecated, use inspect\\.signature\\(\\) instead', re.IGNORECASE), <class 'DeprecationWarning'>, re.compile(''), 0), ('ignore', re.compile("'U' mode is deprecated", re.IGNORECASE), <class 'DeprecationWarning'>, re.compile(''), 0), ('ignore', re.compile('The value of convert_charrefs will become True in 3\\.5\\. You are encouraged to set the value explicitly\\.', re.IGNORECASE), <class 'DeprecationWarning'>, re.compile(''), 0), ('ignore', re.compile('The strict argument and mode are deprecated\\.', re.IGNORECASE), <class 'DeprecationWarning'>, re.compile(''), 0), ('error', re.compile('.*', re.IGNORECASE), <class 'DeprecationWarning'>, re.compile(''), 0)]

Exactly the same in 3.5, except the tests do not fail…

Ah, I think now I see why - at some point in the tests the general DeprecationWarning filter is replaced by four filters for specific warnings, and all other are turned into ('error', re.compile('.*', re.IGNORECASE), <class 'DeprecationWarning'>, re.compile(''), 0) But since the inspect warning between 3.5 and 3.6 was changed from "use inspect.signature() instead" to "use inspect.signature() or inspect.getfullargspec()", the filter fails in the latter.

Any ideas if this is part of the astropy-specific pytest setup, or where to change it?