Skip to content

ModuleNotFoundError for opentelemetry.semconv and ImportError for trace in tox -e py39-test-util-http` #2633

@zhihali

Description

@zhihali

Describe your environment

OS: MacOS with apple chip
Python version: 3.12
Package version: newest

What happened?

When running tox -e py39-test-util-http, I encounter ModuleNotFoundError and ImportError errors. Specifically, the opentelemetry.semconv module cannot be found, and there is an import error for the trace module.

When I run tox -e py39-test-util-http
I will get errors:

__________________________________________________________________________ ERROR collecting util/opentelemetry-util-http/tests/test_capture_custom_headers.py __________________________________________________________________________
ImportError while importing test module '/Users/lizhihan/PycharmProjects/opentelemetry-python-contrib/util/opentelemetry-util-http/tests/test_capture_custom_headers.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniforge3/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
util/opentelemetry-util-http/tests/test_capture_custom_headers.py:18: in <module>
    from opentelemetry.util.http import (
.tox/py39-test-util-http/lib/python3.9/site-packages/opentelemetry/util/http/__init__.py:25: in <module>
    from opentelemetry.semconv.trace import SpanAttributes
E   ModuleNotFoundError: No module named 'opentelemetry.semconv'
________________________________________________________________________________ ERROR collecting util/opentelemetry-util-http/tests/test_http_base.py _________________________________________________________________________________
ImportError while importing test module '/Users/lizhihan/PycharmProjects/opentelemetry-python-contrib/util/opentelemetry-util-http/tests/test_http_base.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniforge3/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
util/opentelemetry-util-http/tests/test_http_base.py:17: in <module>
    from opentelemetry import trace
E   ImportError: cannot import name 'trace' from 'opentelemetry' (unknown location)

Steps to Reproduce

$ brew install python

$ python3 -m venv venv

$ source venv/bin/activate

$ pip install tox

$ pip install opentelemetry-api

$ pip install opentelemetry-sdk

$ tox -e py312-test-util-http

Expected Result

the tox will run successfully

Actual Result

__________________________________________________________________________ ERROR collecting util/opentelemetry-util-http/tests/test_capture_custom_headers.py __________________________________________________________________________
ImportError while importing test module '/Users/lizhihan/PycharmProjects/opentelemetry-python-contrib/util/opentelemetry-util-http/tests/test_capture_custom_headers.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniforge3/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
util/opentelemetry-util-http/tests/test_capture_custom_headers.py:18: in <module>
    from opentelemetry.util.http import (
.tox/py39-test-util-http/lib/python3.9/site-packages/opentelemetry/util/http/__init__.py:25: in <module>
    from opentelemetry.semconv.trace import SpanAttributes
E   ModuleNotFoundError: No module named 'opentelemetry.semconv'
________________________________________________________________________________ ERROR collecting util/opentelemetry-util-http/tests/test_http_base.py _________________________________________________________________________________
ImportError while importing test module '/Users/lizhihan/PycharmProjects/opentelemetry-python-contrib/util/opentelemetry-util-http/tests/test_http_base.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniforge3/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
util/opentelemetry-util-http/tests/test_http_base.py:17: in <module>
    from opentelemetry import trace
E   ImportError: cannot import name 'trace' from 'opentelemetry' (unknown location)
____________________________________________________________________________ ERROR collecting util/opentelemetry-util-http/tests/test_http_excluded_urls.py ____________________________________________________________________________
ImportError while importing test module '/Users/lizhihan/PycharmProjects/opentelemetry-python-contrib/util/opentelemetry-util-http/tests/test_http_excluded_urls.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniforge3/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
util/opentelemetry-util-http/tests/test_http_excluded_urls.py:18: in <module>
    from opentelemetry.util.http import get_excluded_urls
.tox/py39-test-util-http/lib/python3.9/site-packages/opentelemetry/util/http/__init__.py:25: in <module>
    from opentelemetry.semconv.trace import SpanAttributes
E   ModuleNotFoundError: No module named 'opentelemetry.semconv'
____________________________________________________________________________ ERROR collecting util/opentelemetry-util-http/tests/test_remove_credentials.py ____________________________________________________________________________
ImportError while importing test module '/Users/lizhihan/PycharmProjects/opentelemetry-python-contrib/util/opentelemetry-util-http/tests/test_remove_credentials.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniforge3/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
util/opentelemetry-util-http/tests/test_remove_credentials.py:3: in <module>
    from opentelemetry.util.http import remove_url_credentials
.tox/py39-test-util-http/lib/python3.9/site-packages/opentelemetry/util/http/__init__.py:25: in <module>
    from opentelemetry.semconv.trace import SpanAttributes
E   ModuleNotFoundError: No module named 'opentelemetry.semconv'
_____________________________________________________________________________ ERROR collecting util/opentelemetry-util-http/tests/test_sanitize_method.py ______________________________________________________________________________
ImportError while importing test module '/Users/lizhihan/PycharmProjects/opentelemetry-python-contrib/util/opentelemetry-util-http/tests/test_sanitize_method.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniforge3/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
util/opentelemetry-util-http/tests/test_sanitize_method.py:18: in <module>
    from opentelemetry.util.http import (
.tox/py39-test-util-http/lib/python3.9/site-packages/opentelemetry/util/http/__init__.py:25: in <module>
    from opentelemetry.semconv.trace import SpanAttributes
E   ModuleNotFoundError: No module named 'opentelemetry.semconv'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================================================================== 5 errors in 0.08s ===========================================================================================================

Additional context

No response

Would you like to implement a fix?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions