michaelkryukov / mongomock_motor

Library for mocking AsyncIOMotorClient built on top of mongomock.
MIT License
94 stars 23 forks source link

Module fails to load on Python 3.12 #54

Open tiltowait opened 1 month ago

tiltowait commented 1 month ago

I get the following error trying to import mongomock-motor in Python 3.12. I have run python3.12 -m ensurepip --upgrade, which is a commonly suggested fix for this issue with pkgutil.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/tiltowait/Library/Caches/pypoetry/virtualenvs/botch-no4dKFGX-py3.12/lib/python3.12/site-packages/mongomock_motor/__init__.py", line 7, in <module>
    from mongomock import Collection as MongoMockCollection
  File "/Users/tiltowait/Library/Caches/pypoetry/virtualenvs/botch-no4dKFGX-py3.12/lib/python3.12/site-packages/mongomock/__init__.py", line 79, in <module>
    from mongomock.__version__ import __version__
  File "/Users/tiltowait/Library/Caches/pypoetry/virtualenvs/botch-no4dKFGX-py3.12/lib/python3.12/site-packages/mongomock/__version__.py", line 1, in <module>
    import pkg_resources
  File "/Users/tiltowait/Library/Caches/pypoetry/virtualenvs/botch-no4dKFGX-py3.12/lib/python3.12/site-packages/pkg_resources/__init__.py", line 2191, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

I'm using mongomock-motor 0.0.30, poetry 1.8.3, and Python 3.12.3.

michaelkryukov commented 18 hours ago

Looks like an issue with mongomock that can be fixed in https://github.com/mongomock/mongomock/issues/889. While this version is unavailable, did you try to install setuptools? It seems to help:

mongomock_motor/$ python3 -V
Python 3.12.4
mongomock_motor/$ python3 -m venv .venv
mongomock_motor/$ source .venv/bin/activate
mongomock_motor/$ python3 -m pip install -r requirements.txt setuptools
...
mongomock_motor/$ make test
... 32 passed ...