pytest-dev / pytest-django

A Django plugin for pytest.
https://pytest-django.readthedocs.io/
Other
1.33k stars 341 forks source link

ImportError: cannot import name 'Mapping' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py) #985

Closed lemaadi closed 8 months ago

lemaadi commented 2 years ago

Hi,

We are facing this issue when building a django project in docker env with docker-compose build command

ImportError: cannot import name 'Mapping' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)

pytest-django found a Django project in . (it contains manage.py) and added it to the Python path.
If this is wrong, add "django_find_project = false" to pytest.ini and explicitly manage your Python path.

In the following situation :

Thank's in advance

bluetech commented 2 years ago

pytest-django does not try to import Mapping from collections, so the problem is not in this project. You'll need to find which code performs this import. You can search for a line such as from collections import Mapping (it might not be that exactly).

lemaadi commented 2 years ago

Thank's @bluetech for your reply 👍

I already checked that but there is no such import in the project's code 🤔

bluetech commented 2 years ago

If you are using a virtualenv, check inside the virtualenv directory as well. This will tell you if any dependency is importing it.

EvanCarroll commented 1 year ago

I'm also getting this error, and I can't figure out what's doing it. I've searched for the string from collections import Mapping and I have no examples. Is there a way to stub this out such that an import succeeds and dies. It's horrible that the stacktrace here is so bad. Not sure what's responsible for that, core python or django but I would expect for an import failed to tell me where the caller was.