python-attrs / cattrs

Composable custom class converters for attrs, dataclasses and friends.
https://catt.rs
MIT License
828 stars 113 forks source link

[macOS] Error when trying to run tests: `ImportError: cannot import name 'CodecOptions' from 'bson'` #523

Open barracuda156 opened 8 months ago

barracuda156 commented 8 months ago

Description

Running tests does not seem to work.

What I Did

--->  Testing py312-cattrs
Executing:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-cattrs/py312-cattrs/work/cattrs-23.2.3" && py.test-3.12 -o addopts='' 
============================= test session starts ==============================
platform darwin -- Python 3.12.2, pytest-7.4.3, pluggy-1.3.0
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-cattrs/py312-cattrs/work/cattrs-23.2.3
configfile: pyproject.toml
plugins: hypothesis-6.92.1, benchmark-4.0.0
collected 626 items / 1 error

==================================== ERRORS ====================================
____________________ ERROR collecting tests/test_preconf.py ____________________
ImportError while importing test module '/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-cattrs/py312-cattrs/work/cattrs-23.2.3/tests/test_preconf.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_preconf.py:11: in <module>
    from bson import CodecOptions, ObjectId
E   ImportError: cannot import name 'CodecOptions' from 'bson' (/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/bson/__init__.py)
=============================== warnings summary ===============================
tests/typed.py:417
  /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-cattrs/py312-cattrs/work/cattrs-23.2.3/tests/typed.py:417: HypothesisWarning: Return-type annotation is `st.SearchStrategy[typing.Tuple[attr._make._CountingAttr, st.SearchStrategy]]`, but the decorated function should return a value (not a strategy)
    @composite

tests/typed.py:826
  /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-cattrs/py312-cattrs/work/cattrs-23.2.3/tests/typed.py:826: HypothesisWarning: Return-type annotation is `st.SearchStrategy[typing.Tuple[typing.Type, st.SearchStrategy[typing.Tuple[typing.Any]], st.SearchStrategy[typing.Dict[str, typing.Any]]]]`, but the decorated function should return a value (not a strategy)
    @composite

../../../../../../../Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/dateutil/tz/tz.py:37
  /opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/dateutil/tz/tz.py:37: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    EPOCH = datetime.datetime.utcfromtimestamp(0)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
ERROR tests/test_preconf.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
========================= 3 warnings, 1 error in 6.83s =========================
Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-cattrs/py312-cattrs/work/cattrs-23.2.3" && py.test-3.12 -o addopts='' 
Exit code: 2
Tinche commented 8 months ago

Is your virtual environment set up properly, and did you use PDM (the packaging tool we use) to set it up using the lockfile? It's failing to import CodecOptions from the bson module, which leads me to believe you either have the bson package installed (it should be pymongo instead), or the wrong version of pymongo.

barracuda156 commented 8 months ago

which leads me to believe you either have the bson package installed (it should be pymongo instead)

@Tinche Yeah, this is it, thank you. Let me see if the latter builds.