From e009943d5819472ce8191f10b3114bbfe0bee2b3 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 29 Jul 2025 15:11:17 +0200 Subject: [PATCH 1/2] setup: Add missing azurestorage pytest marker --- setup.cfg | 1 + tests/scripts/envs/azure.sh | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/scripts/envs/azure.sh diff --git a/setup.cfg b/setup.cfg index 7532a5ad6..d3611a899 100644 --- a/setup.cfg +++ b/setup.cfg @@ -107,6 +107,7 @@ markers = aiobotocore kafka grpc + azurestorage addopts=--random-order [isort] diff --git a/tests/scripts/envs/azure.sh b/tests/scripts/envs/azure.sh new file mode 100644 index 000000000..d190b5882 --- /dev/null +++ b/tests/scripts/envs/azure.sh @@ -0,0 +1 @@ +export PYTEST_MARKER="-m azurestorage" From 01b3dfaaccdc090fbcf63bbc3afb1361303c7bb5 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 30 Jul 2025 12:44:43 +0200 Subject: [PATCH 2/2] tests: use unittest.mock instead of mock Use the standard library module instead of the backported package. Should fix mocks failures with Python 3.13. --- tests/client/client_tests.py | 2 +- tests/client/exception_tests.py | 2 +- tests/client/py3_exception_tests.py | 2 +- tests/config/central_config_tests.py | 3 ++- tests/config/tests.py | 2 +- tests/contrib/asyncio/aiohttp_web_tests.py | 3 ++- tests/contrib/asyncio/starlette_tests.py | 2 +- tests/contrib/asyncio/tornado/tornado_tests.py | 2 +- tests/contrib/celery/flask_tests.py | 2 +- tests/contrib/django/django_tests.py | 2 +- tests/contrib/django/wrapper_tests.py | 2 +- tests/contrib/flask/flask_tests.py | 2 +- .../serverless/azurefunctions/azure_functions_tests.py | 2 +- tests/events/tests.py | 3 ++- tests/fixtures.py | 2 +- tests/instrumentation/base_tests.py | 2 +- tests/instrumentation/transactions_store_tests.py | 2 +- tests/instrumentation/urllib_tests.py | 2 +- tests/metrics/base_tests.py | 2 +- tests/metrics/breakdown_tests.py | 3 ++- tests/processors/tests.py | 6 ++++-- tests/requirements/lint-isort.txt | 1 - tests/requirements/reqs-base.txt | 1 - tests/transports/test_base.py | 2 +- tests/transports/test_urllib3.py | 2 +- tests/utils/cloud_tests.py | 2 +- tests/utils/compat_tests.py | 3 ++- tests/utils/stacks/tests.py | 2 +- tests/utils/threading_tests.py | 2 +- 29 files changed, 35 insertions(+), 30 deletions(-) diff --git a/tests/client/client_tests.py b/tests/client/client_tests.py index 62e10d301..05388921f 100644 --- a/tests/client/client_tests.py +++ b/tests/client/client_tests.py @@ -39,8 +39,8 @@ import time import warnings from collections import defaultdict +from unittest import mock -import mock import pytest from pytest_localserver.http import ContentServer from pytest_localserver.https import DEFAULT_CERTIFICATE diff --git a/tests/client/exception_tests.py b/tests/client/exception_tests.py index 082835be3..056f23548 100644 --- a/tests/client/exception_tests.py +++ b/tests/client/exception_tests.py @@ -29,8 +29,8 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os +from unittest import mock -import mock import pytest import elasticapm diff --git a/tests/client/py3_exception_tests.py b/tests/client/py3_exception_tests.py index ad8bb10ca..e1ff057eb 100644 --- a/tests/client/py3_exception_tests.py +++ b/tests/client/py3_exception_tests.py @@ -38,7 +38,7 @@ # # -import mock +from unittest import mock from elasticapm.conf.constants import ERROR diff --git a/tests/config/central_config_tests.py b/tests/config/central_config_tests.py index 568cf180a..d3aaf4fe7 100644 --- a/tests/config/central_config_tests.py +++ b/tests/config/central_config_tests.py @@ -28,7 +28,8 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import mock +from unittest import mock + import pytest diff --git a/tests/config/tests.py b/tests/config/tests.py index 284f5694a..ba07d7795 100644 --- a/tests/config/tests.py +++ b/tests/config/tests.py @@ -35,8 +35,8 @@ import platform import stat from datetime import timedelta +from unittest import mock -import mock import pytest import elasticapm.conf diff --git a/tests/contrib/asyncio/aiohttp_web_tests.py b/tests/contrib/asyncio/aiohttp_web_tests.py index 929a8e1a7..4a63d8714 100644 --- a/tests/contrib/asyncio/aiohttp_web_tests.py +++ b/tests/contrib/asyncio/aiohttp_web_tests.py @@ -32,7 +32,8 @@ aiohttp = pytest.importorskip("aiohttp") # isort:skip -import mock +from unittest import mock + from multidict import MultiDict import elasticapm diff --git a/tests/contrib/asyncio/starlette_tests.py b/tests/contrib/asyncio/starlette_tests.py index 38c51fa08..4053b5d5b 100644 --- a/tests/contrib/asyncio/starlette_tests.py +++ b/tests/contrib/asyncio/starlette_tests.py @@ -38,8 +38,8 @@ starlette = pytest.importorskip("starlette") # isort:skip import os +from unittest import mock -import mock import urllib3 import wrapt from starlette.applications import Starlette diff --git a/tests/contrib/asyncio/tornado/tornado_tests.py b/tests/contrib/asyncio/tornado/tornado_tests.py index 3ce3bafed..337d54942 100644 --- a/tests/contrib/asyncio/tornado/tornado_tests.py +++ b/tests/contrib/asyncio/tornado/tornado_tests.py @@ -33,8 +33,8 @@ tornado = pytest.importorskip("tornado") # isort:skip import os +from unittest import mock -import mock from wrapt import BoundFunctionWrapper import elasticapm diff --git a/tests/contrib/celery/flask_tests.py b/tests/contrib/celery/flask_tests.py index 29dd61fdb..cb7c53ed5 100644 --- a/tests/contrib/celery/flask_tests.py +++ b/tests/contrib/celery/flask_tests.py @@ -33,7 +33,7 @@ flask = pytest.importorskip("flask") # isort:skip celery = pytest.importorskip("celery") # isort:skip -import mock +from unittest import mock from elasticapm.conf.constants import ERROR, TRANSACTION diff --git a/tests/contrib/django/django_tests.py b/tests/contrib/django/django_tests.py index 529d56a69..312583ac1 100644 --- a/tests/contrib/django/django_tests.py +++ b/tests/contrib/django/django_tests.py @@ -41,8 +41,8 @@ import logging import os from copy import deepcopy +from unittest import mock -import mock from django.conf import settings from django.contrib.auth.models import User from django.contrib.redirects.models import Redirect diff --git a/tests/contrib/django/wrapper_tests.py b/tests/contrib/django/wrapper_tests.py index 4c3f186fc..6464f17b7 100644 --- a/tests/contrib/django/wrapper_tests.py +++ b/tests/contrib/django/wrapper_tests.py @@ -32,7 +32,7 @@ # Installing an app is not reversible, so using this instrumentation "for real" would # pollute the Django instance used by pytest. -import mock +from unittest import mock from elasticapm.instrumentation.packages.django import DjangoAutoInstrumentation diff --git a/tests/contrib/flask/flask_tests.py b/tests/contrib/flask/flask_tests.py index 8d893533b..38657a6f6 100644 --- a/tests/contrib/flask/flask_tests.py +++ b/tests/contrib/flask/flask_tests.py @@ -35,9 +35,9 @@ import io import logging import os +from unittest import mock from urllib.request import urlopen -import mock from flask import signals import elasticapm diff --git a/tests/contrib/serverless/azurefunctions/azure_functions_tests.py b/tests/contrib/serverless/azurefunctions/azure_functions_tests.py index e2abbdcd3..91550a59f 100644 --- a/tests/contrib/serverless/azurefunctions/azure_functions_tests.py +++ b/tests/contrib/serverless/azurefunctions/azure_functions_tests.py @@ -33,9 +33,9 @@ import datetime import os +from unittest import mock import azure.functions as func -import mock import elasticapm from elasticapm.conf import constants diff --git a/tests/events/tests.py b/tests/events/tests.py index cd6cc6d3c..89d33ca3b 100644 --- a/tests/events/tests.py +++ b/tests/events/tests.py @@ -32,8 +32,9 @@ from __future__ import absolute_import +from unittest.mock import Mock + import pytest -from mock import Mock from elasticapm.events import Exception, Message diff --git a/tests/fixtures.py b/tests/fixtures.py index ddeaa1f5b..9d69d80cb 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -46,10 +46,10 @@ import zlib from collections import defaultdict from typing import Optional +from unittest import mock from urllib.request import pathname2url import jsonschema -import mock import pytest from pytest_localserver.http import ContentServer from werkzeug.wrappers import Request, Response diff --git a/tests/instrumentation/base_tests.py b/tests/instrumentation/base_tests.py index da2e265ed..9e92aa29c 100644 --- a/tests/instrumentation/base_tests.py +++ b/tests/instrumentation/base_tests.py @@ -31,8 +31,8 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import logging +from unittest import mock -import mock import pytest import wrapt diff --git a/tests/instrumentation/transactions_store_tests.py b/tests/instrumentation/transactions_store_tests.py index 23a8d0b2a..2d1dcefcc 100644 --- a/tests/instrumentation/transactions_store_tests.py +++ b/tests/instrumentation/transactions_store_tests.py @@ -32,8 +32,8 @@ import logging import time from collections import defaultdict +from unittest import mock -import mock import pytest import elasticapm diff --git a/tests/instrumentation/urllib_tests.py b/tests/instrumentation/urllib_tests.py index fbf5fa44f..62dda0402 100644 --- a/tests/instrumentation/urllib_tests.py +++ b/tests/instrumentation/urllib_tests.py @@ -28,10 +28,10 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import urllib.parse +from unittest import mock from urllib.error import HTTPError, URLError from urllib.request import urlopen -import mock import pytest from elasticapm.conf import constants diff --git a/tests/metrics/base_tests.py b/tests/metrics/base_tests.py index 526e5079c..a9c51fb34 100644 --- a/tests/metrics/base_tests.py +++ b/tests/metrics/base_tests.py @@ -31,8 +31,8 @@ import logging import time from multiprocessing.dummy import Pool +from unittest import mock -import mock import pytest from elasticapm.conf import constants diff --git a/tests/metrics/breakdown_tests.py b/tests/metrics/breakdown_tests.py index 3e6b7ed9e..8572bcf6a 100644 --- a/tests/metrics/breakdown_tests.py +++ b/tests/metrics/breakdown_tests.py @@ -28,7 +28,8 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import mock +from unittest import mock + import pytest import elasticapm diff --git a/tests/processors/tests.py b/tests/processors/tests.py index 772eccf72..84fdfb2b9 100644 --- a/tests/processors/tests.py +++ b/tests/processors/tests.py @@ -34,8 +34,8 @@ import logging import os +from unittest import mock -import mock import pytest import elasticapm @@ -464,7 +464,9 @@ def test_drop_events_in_processor(elasticapm_client, caplog): assert shouldnt_be_called_processor.call_count == 0 assert elasticapm_client._transport.events[TRANSACTION][0] is None assert_any_record_contains( - caplog.records, "Dropped event of type transaction due to processor mock.mock.dropper", "elasticapm.transport" + caplog.records, + "Dropped event of type transaction due to processor unittest.mock.dropper", + "elasticapm.transport", ) diff --git a/tests/requirements/lint-isort.txt b/tests/requirements/lint-isort.txt index 16ad5274c..2a7924352 100644 --- a/tests/requirements/lint-isort.txt +++ b/tests/requirements/lint-isort.txt @@ -1,2 +1 @@ isort -mock diff --git a/tests/requirements/reqs-base.txt b/tests/requirements/reqs-base.txt index 0ce35a889..ff6e4d24c 100644 --- a/tests/requirements/reqs-base.txt +++ b/tests/requirements/reqs-base.txt @@ -14,7 +14,6 @@ jsonschema==4.17.3 urllib3!=2.0.0,<3.0.0 certifi Logbook -mock pytz ecs_logging structlog diff --git a/tests/transports/test_base.py b/tests/transports/test_base.py index 2f77c3e95..37250cf7c 100644 --- a/tests/transports/test_base.py +++ b/tests/transports/test_base.py @@ -35,8 +35,8 @@ import sys import time import timeit +from unittest import mock -import mock import pytest from elasticapm.transport.base import Transport, TransportState diff --git a/tests/transports/test_urllib3.py b/tests/transports/test_urllib3.py index 32a5b7384..e53cb91e8 100644 --- a/tests/transports/test_urllib3.py +++ b/tests/transports/test_urllib3.py @@ -31,9 +31,9 @@ import os import time +from unittest import mock import certifi -import mock import pytest import urllib3.poolmanager from urllib3.exceptions import MaxRetryError, TimeoutError diff --git a/tests/utils/cloud_tests.py b/tests/utils/cloud_tests.py index 07c1f82e0..a365c2c93 100644 --- a/tests/utils/cloud_tests.py +++ b/tests/utils/cloud_tests.py @@ -29,8 +29,8 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os +from unittest import mock -import mock import urllib3 import elasticapm.utils.cloud diff --git a/tests/utils/compat_tests.py b/tests/utils/compat_tests.py index 9da7ac2f8..352d0bb48 100644 --- a/tests/utils/compat_tests.py +++ b/tests/utils/compat_tests.py @@ -28,7 +28,8 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import mock +from unittest import mock + import pytest from elasticapm.utils import compat diff --git a/tests/utils/stacks/tests.py b/tests/utils/stacks/tests.py index c4be88ff2..6b3ba0f89 100644 --- a/tests/utils/stacks/tests.py +++ b/tests/utils/stacks/tests.py @@ -34,9 +34,9 @@ import os import pkgutil +from unittest.mock import Mock import pytest -from mock import Mock import elasticapm from elasticapm.conf import constants diff --git a/tests/utils/threading_tests.py b/tests/utils/threading_tests.py index 1c7329cd9..d9f2bf651 100644 --- a/tests/utils/threading_tests.py +++ b/tests/utils/threading_tests.py @@ -29,8 +29,8 @@ import platform import time +from unittest import mock -import mock import pytest from elasticapm.utils.threading import IntervalTimer