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

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

Open
barracuda156 opened this issue Mar 18, 2024 · 2 comments
Labels
more-info-needed More information required.

Comments

@barracuda156
Copy link

  • cattrs version: 23.2.3
  • Python version: 3.12
  • Operating System: macOS 10.6

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
Copy link
Member

Tinche commented Mar 18, 2024

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.

@Tinche Tinche added the more-info-needed More information required. label Mar 18, 2024
@barracuda156
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-info-needed More information required.
Projects
None yet
Development

No branches or pull requests

2 participants