Skip to content

8.13.1: pytest fails with ImportError: cannot import name 'OrjsonSerializer' from 'elasticsearch.serializer in elasticsearch/serializer.py #2560

Closed
@kloczek

Description

@kloczek

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix> using installer module
  • run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
  • build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")
Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-elasticsearch-8.13.1-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-elasticsearch-8.13.1-2.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/tkloczko/rpmbuild/BUILD/elasticsearch-py-8.13.1
configfile: setup.cfg
plugins: twisted-1.14.1, trio-0.8.0, tornasync-0.6.0.post2, anyio-4.3.0, asyncio-0.23.6
asyncio: mode=strict
collected 361 items / 1 error

========================================================================================== ERRORS ===========================================================================================
__________________________________________________________________ ERROR collecting test_elasticsearch/test_serializer.py ___________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/elasticsearch-py-8.13.1/test_elasticsearch/test_serializer.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_elasticsearch/test_serializer.py:35: in <module>
    from elasticsearch.serializer import JSONSerializer, OrjsonSerializer, TextSerializer
E   ImportError: cannot import name 'OrjsonSerializer' from 'elasticsearch.serializer' (/home/tkloczko/rpmbuild/BUILD/elasticsearch-py-8.13.1/elasticsearch/serializer.py)
===================================================================================== warnings summary ======================================================================================
../../../../../usr/lib/python3.10/site-packages/_pytest/fixtures.py:1314
  /usr/lib/python3.10/site-packages/_pytest/fixtures.py:1314: PytestRemovedIn9Warning: Marks applied to fixtures have no effect
  See docs: https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function
    return fixture_marker(fixture_function)

elasticsearch/_sync/client/__init__.py:399
  /home/tkloczko/rpmbuild/BUILD/elasticsearch-py-8.13.1/elasticsearch/_sync/client/__init__.py:399: SecurityWarning: Connecting to 'https://localhost:9200' using TLS with verify_certs=False is insecure
    _transport = transport_class(

test_elasticsearch/test_server/test_rest_api_spec.py:641
  /home/tkloczko/rpmbuild/BUILD/elasticsearch-py-8.13.1/test_elasticsearch/test_server/test_rest_api_spec.py:641: UserWarning: Could not load REST API tests: Could not connect to Elasticsearch (tried https://localhost:9200, http://localhost:9200, https://elastic:changeme@localhost:9200, http://elastic:changeme@localhost:9200): Connection error caused by: ConnectionError(Connection error caused by: NewConnectionError(<elastic_transport._node._urllib3_chain_certs.HTTPSConnection object at 0x7efc318a5f60>: Failed to establish a new connection: [Errno 111] Connection refused))
    warnings.warn(f"Could not load REST API tests: {str(e)}")

test_elasticsearch/test_async/test_transport.py:497
  test_elasticsearch/test_async/test_transport.py:497: PytestDeprecationWarning: test_sniff_after_n_seconds is asynchronous and explicitly requests the "event_loop" fixture. Asynchronous fixtures and test functions should use "asyncio.get_running_loop()" instead.
    async def test_sniff_after_n_seconds(self, event_loop):

test_elasticsearch/test_async/test_transport.py:551
  test_elasticsearch/test_async/test_transport.py:551: PytestDeprecationWarning: test_sniff_on_start_close_unlocks_async_calls is asynchronous and explicitly requests the "event_loop" fixture. Asynchronous fixtures and test functions should use "asyncio.get_running_loop()" instead.
    async def test_sniff_on_start_close_unlocks_async_calls(self, event_loop):

test_elasticsearch/test_transport.py:36
  /home/tkloczko/rpmbuild/BUILD/elasticsearch-py-8.13.1/test_elasticsearch/test_transport.py:36: DeprecationWarning: Importing from the 'elasticsearch.transport' module is deprecated. Instead import from 'elastic_transport'
    from elasticsearch.transport import get_host_info

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
ERROR test_elasticsearch/test_serializer.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================================================== 6 warnings, 1 error in 1.48s ================================================================================

In above output it is possible to see some pytest warnings as well

List of installed modules in build env:
Package                       Version
----------------------------- -----------
aiohttp                       3.9.5
aiosignal                     1.3.1
alabaster                     0.7.16
anyio                         4.3.0
async-timeout                 4.0.3
attrs                         23.2.0
Automat                       22.10.0
Babel                         2.15.0
build                         1.2.1
certifi                       2023.7.22
charset-normalizer            3.3.2
constantly                    23.10.4
decorator                     5.1.1
defusedxml                    0.7.1
docutils                      0.20.1
elastic-transport             8.13.0
exceptiongroup                1.1.3
frozenlist                    1.4.1
greenlet                      3.0.3
hyperlink                     21.0.0
idna                          3.7
imagesize                     1.4.1
importlib_metadata            7.1.0
incremental                   22.10.0
iniconfig                     2.0.0
installer                     0.7.0
Jinja2                        3.1.4
MarkupSafe                    2.1.5
multidict                     6.0.5
outcome                       1.2.0
packaging                     24.0
pluggy                        1.4.0
Pygments                      2.18.0
pyproject_hooks               1.0.0
pytest                        8.1.1
pytest-asyncio                0.23.6
pytest-tornasync              0.6.0.post2
pytest-trio                   0.8.0
pytest-twisted                1.14.1
python-dateutil               2.9.0.post0
PyYAML                        6.0.1
requests                      2.31.0
setuptools                    69.4.0
sniffio                       1.3.0
snowballstemmer               2.2.0
sortedcontainers              2.4.0
Sphinx                        7.3.7
sphinx_rtd_theme              2.0.0
sphinxcontrib-applehelp       1.0.8
sphinxcontrib-devhelp         1.0.6
sphinxcontrib-htmlhelp        2.0.5
sphinxcontrib-jquery          4.1
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.7
sphinxcontrib-serializinghtml 1.1.10
tokenize_rt                   5.2.0
tomli                         2.0.1
tornado                       6.3.3
trio                          0.25.0
Twisted                       24.3.0
typing_extensions             4.11.0
urllib3                       2.2.1
wheel                         0.43.0
yarl                          1.9.4
zipp                          3.18.2
zope.event                    5.0
zope.interface                6.4

Please let me know if you need more details or want me to perform some diagnostics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions