Skip to content
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

deprecation warnings when imported on python 3.7 beta #3339

Closed
irmen opened this issue Mar 24, 2018 · 26 comments
Closed

deprecation warnings when imported on python 3.7 beta #3339

irmen opened this issue Mar 24, 2018 · 26 comments
Labels
plugin: warnings related to the warnings builtin plugin type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog type: bug problem that needs to be addressed type: deprecation feature that will be removed in the future type: infrastructure improvement to development/releases/CI structure

Comments

@irmen
Copy link
Contributor

irmen commented Mar 24, 2018

Python 3.7 will introduce a few new API deprecation warnings. They're triggered when importing pytest on python 3.7 beta:

11:20 $ python3.7 -Wall 
Python 3.7.0b2+ (heads/3.7:3b4c6b16c5, Mar 22 2018, 23:55:22) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import  pytest
/home/irmen/.local/lib/python3.7/site-packages/_pytest/assertion/util.py:8: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Sequence
/home/irmen/.local/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:6: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
/home/irmen/.local/lib/python3.7/site-packages/_pytest/mark/structures.py:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import namedtuple, MutableMapping as MappingMixin
>>> pytest.__version__
'3.5.0'
>>> 

pytest version: 3.5.0
python version: cpython 3.7 built from source (3.7 branch)
OS: debian 9

@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #2191 (add an option to warn about Python 3.x possible incompatibilities), #2118 (pytest triggering deprecation warnings in 3.0.5), #2327 (capsys not capturing on Python 2.7), #2674 (SystemError: 'finally' pops bad exception with python 3.7 (master branch)), and #2917 (Asserting repeated warning does not work in Python 2.7).

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Mar 24, 2018
@nicoddemus
Copy link
Member

Thanks @irmen for the report!

@nicoddemus nicoddemus added type: infrastructure improvement to development/releases/CI structure plugin: warnings related to the warnings builtin plugin type: deprecation feature that will be removed in the future labels Mar 26, 2018
@RonnyPfannschmidt
Copy link
Member

this si a easy fix - we need to try to import from collections.abc first

@RonnyPfannschmidt RonnyPfannschmidt added the good first issue easy issue that is friendly to new contributor label Mar 27, 2018
@feuillemorte
Copy link
Contributor

collections.abc is easy, but the problem with changing imp to importlib: pytest stops with error:

RuntimeError: maximum recursion depth exceeded while calling a Python object

@RonnyPfannschmidt
Copy link
Member

lets fix the easily fixable first then ^^ i wont have time to investigate soonish

@RonnyPfannschmidt
Copy link
Member

i just tried to fix imp importing, its not actually easy as things are named differently and it needs help on python3

we might need to drop python2 support or spend quite some time for a compat layer
an alternative would be using importlib2 on python2, but that might come with an own can of worms

@RonnyPfannschmidt RonnyPfannschmidt added type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog and removed good first issue easy issue that is friendly to new contributor labels Mar 29, 2018
@irmen
Copy link
Contributor Author

irmen commented Mar 29, 2018

For Serpent, I fixed it with a simple version check like this:
irmen/Serpent@a0bb008#diff-e4eda821e02f4c665914be5d8a0a7a5dR23

@RonnyPfannschmidt
Copy link
Member

@irmen thats good for the abc one ^^ up for making that pr for pytest module?

@irmen
Copy link
Contributor Author

irmen commented Mar 29, 2018

Sure I'm not familiar with the Pytest code base yet but this shouldn't be too hard.

@irmen
Copy link
Contributor Author

irmen commented Mar 29, 2018

note that at least more_itertools which is a dependency, has the same deprecation warning. I guess I'll be stalking them too soon

@irmen
Copy link
Contributor Author

irmen commented Mar 29, 2018

I'm not able to fix the deprecation warnings from using the imp module in assertion/rewrite.py there's a bit too much wizardry going on there

@RonnyPfannschmidt
Copy link
Member

@irmen correct, its quite tricky, please dont try unless you are fluent - i fear we might need to port to importlib/importlib2 in general

@nicoddemus
Copy link
Member

I agree with @RonnyPfannschmidt, that bit is quite tricky I'm afraid.

@hroncok
Copy link
Member

hroncok commented May 22, 2018

We've got a lot of tests failures in Fedora because of this:

testing/python/approx.py FFFFFFFFFFFFFFFFFFFFFFFFFFFss.FFFFFss           [ 80%]

...

E           DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working

We run the testsuite as:

PATH=/builddir/build/BUILDROOT/pytest-3.5.1-1.fc29.x86_64/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/builddir/.local/bin:/builddir/bin
PYTHONPATH=/builddir/build/BUILDROOT/pytest-3.5.1-1.fc29.x86_64/usr/lib/python3.7/site-packages
/builddir/build/BUILDROOT/pytest-3.5.1-1.fc29.x86_64/usr/bin/pytest-3.7 -r s testing

Any hack to get rid of such failures? I've been trying to use -W ignore::DeprecationWarning but it didn't help. Thanks

full log

@nicoddemus
Copy link
Member

@hroncok this has been released in 3.5.1 already, see: https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst#trivialinternal-changes

Not sure why you are still seeing this warnings, here's the code:

pytest/_pytest/compat.py

Lines 41 to 47 in 8e17e32

if _PY3:
from collections.abc import MutableMapping as MappingMixin # noqa
from collections.abc import Sequence # noqa
else:
# those raise DeprecationWarnings in Python >=3.7
from collections import MutableMapping as MappingMixin # noqa
from collections import Sequence # noqa

@hroncok
Copy link
Member

hroncok commented May 22, 2018

This is 3.5.1, that's the weird thing.

@hroncok
Copy link
Member

hroncok commented May 22, 2018

this is in master:

from collections import Mapping, Sequence

@hroncok
Copy link
Member

hroncok commented May 22, 2018

testing with:

diff --git a/_pytest/compat.py b/_pytest/compat.py
index a5fa037..1a4b750 100644
--- a/_pytest/compat.py
+++ b/_pytest/compat.py
@@ -40,11 +40,11 @@ MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError'
 
 if _PY3:
     from collections.abc import MutableMapping as MappingMixin  # noqa
-    from collections.abc import Sequence  # noqa
+    from collections.abc import Mapping, Sequence  # noqa
 else:
     # those raise DeprecationWarnings in Python >=3.7
     from collections import MutableMapping as MappingMixin  # noqa
-    from collections import Sequence  # noqa
+    from collections import Mapping, Sequence  # noqa
 
 
 def _format_args(func):
diff --git a/_pytest/python_api.py b/_pytest/python_api.py
index 8e09a4a..838a4a5 100644
--- a/_pytest/python_api.py
+++ b/_pytest/python_api.py
@@ -426,7 +426,7 @@ def approx(expected, rel=None, abs=None, nan_ok=False):
        __ https://docs.python.org/3/reference/datamodel.html#object.__ge__
     """
 
-    from collections import Mapping, Sequence
+    from _pytest.compat import Mapping, Sequence
     from _pytest.compat import STRING_TYPES as String
     from decimal import Decimal

(Edited to add Mapping to compat)

@RonnyPfannschmidt
Copy link
Member

that one needs to go into 3.6

@nicoddemus
Copy link
Member

@hroncok would you like to open a PR? If we can get this into 3.6 it would be great.

@hroncok
Copy link
Member

hroncok commented May 22, 2018

I'm still testing a build, because the first patch was incomplete. A PR is incoming, just want to confirm it fixes the problem.

@hroncok
Copy link
Member

hroncok commented May 22, 2018

succeeded!

@RonnyPfannschmidt
Copy link
Member

@hroncok please provide a pr - we'd like to include in the next release which is due today or early tommorow

hroncok added a commit to hroncok/pytest that referenced this issue May 22, 2018
Related to pytest-dev#3339

Fixes a DeprecationWarning on Python 3.7

Adds Mapping to compat
hroncok added a commit to hroncok/pytest that referenced this issue May 22, 2018
Related to pytest-dev#3339

Fixes a DeprecationWarning on Python 3.7

Adds Mapping to compat
@hroncok
Copy link
Member

hroncok commented May 22, 2018

I said I'm working on it. Here it is #3497

hroncok added a commit to hroncok/pytest that referenced this issue May 22, 2018
Related to pytest-dev#3339

Fixes a DeprecationWarning on Python 3.7

Adds Mapping to compat
hroncok added a commit to hroncok/pytest that referenced this issue May 22, 2018
Related to pytest-dev#3339

Fixes a DeprecationWarning on Python 3.7

Adds Mapping to compat
@nicoddemus
Copy link
Member

We can close this now, the imp import is already tracked by #1403.

Thanks everyone!

@schlomo
Copy link

schlomo commented Dec 4, 2018

Also reported in boto/botocore#1615

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: warnings related to the warnings builtin plugin type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog type: bug problem that needs to be addressed type: deprecation feature that will be removed in the future type: infrastructure improvement to development/releases/CI structure
Projects
None yet
Development

No branches or pull requests

7 participants