diff --git a/.ci/.matrix_exclude.yml b/.ci/.matrix_exclude.yml index d4b1416b2..db796ee34 100644 --- a/.ci/.matrix_exclude.yml +++ b/.ci/.matrix_exclude.yml @@ -5,13 +5,34 @@ exclude: # Django 4.0 requires Python 3.8+ - VERSION: pypy-3 # current pypy-3 is compatible with Python 3.7 FRAMEWORK: django-4.0 + - VERSION: python-3.6 + FRAMEWORK: django-4.0 + - VERSION: python-3.7 + FRAMEWORK: django-4.0 + # Django 4.2 requires Python 3.8+ + - VERSION: python-3.6 + FRAMEWORK: django-4.2 + - VERSION: python-3.7 + FRAMEWORK: django-4.2 # Django 5.0 requires Python 3.10+ + - VERSION: python-3.6 + FRAMEWORK: django-5.0 + - VERSION: python-3.7 + FRAMEWORK: django-5.0 - VERSION: python-3.8 FRAMEWORK: django-5.0 - VERSION: python-3.9 FRAMEWORK: django-5.0 - VERSION: pypy-3 # current pypy-3 is compatible with Python 3.7 FRAMEWORK: celery-5-django-4 + - VERSION: python-3.6 + FRAMEWORK: celery-5-django-4 + - VERSION: python-3.7 + FRAMEWORK: celery-5-django-4 + - VERSION: python-3.6 + FRAMEWORK: celery-5-django-5 + - VERSION: python-3.7 + FRAMEWORK: celery-5-django-5 - VERSION: python-3.8 FRAMEWORK: celery-5-django-5 - VERSION: python-3.9 @@ -19,6 +40,18 @@ exclude: # Flask - VERSION: pypy-3 FRAMEWORK: flask-0.11 # see https://github.com/pallets/flask/commit/6e46d0cd, 0.11.2 was never released + - VERSION: python-3.6 + FRAMEWORK: flask-2.1 + - VERSION: python-3.6 + FRAMEWORK: flask-2.2 + - VERSION: python-3.6 + FRAMEWORK: flask-2.3 + - VERSION: python-3.6 + FRAMEWORK: flask-3.0 + - VERSION: python-3.7 + FRAMEWORK: flask-2.3 + - VERSION: python-3.7 + FRAMEWORK: flask-3.0 # Python 3.10 removed a bunch of classes from collections, now in collections.abc - VERSION: python-3.10 FRAMEWORK: django-1.11 @@ -152,6 +185,8 @@ exclude: # pymssql - VERSION: pypy-3 # currently fails with error on pypy3 FRAMEWORK: pymssql-newest + - VERSION: python-3.6 # dropped support for py3.6 + FRAMEWORK: pymssql-newest # pyodbc - VERSION: pypy-3 FRAMEWORK: pyodbc-newest @@ -175,28 +210,48 @@ exclude: # aiohttp client, only supported in Python 3.7+ - VERSION: pypy-3 FRAMEWORK: aiohttp-3.0 + - VERSION: python-3.6 + FRAMEWORK: aiohttp-3.0 - VERSION: pypy-3 FRAMEWORK: aiohttp-4.0 + - VERSION: python-3.6 + FRAMEWORK: aiohttp-4.0 - VERSION: pypy-3 FRAMEWORK: aiohttp-newest + - VERSION: python-3.6 + FRAMEWORK: aiohttp-newest # tornado, only supported in Python 3.7+ - VERSION: pypy-3 FRAMEWORK: tornado-newest + - VERSION: python-3.6 + FRAMEWORK: tornado-newest # Starlette, only supported in python 3.7+ - VERSION: pypy-3 FRAMEWORK: starlette-0.13 + - VERSION: python-3.6 + FRAMEWORK: starlette-0.13 - VERSION: pypy-3 FRAMEWORK: starlette-0.14 + - VERSION: python-3.6 + FRAMEWORK: starlette-0.14 - VERSION: pypy-3 FRAMEWORK: starlette-newest + - VERSION: python-3.6 + FRAMEWORK: starlette-newest # aiopg - VERSION: pypy-3 FRAMEWORK: aiopg-newest + - VERSION: python-3.6 + FRAMEWORK: aiopg-newest # asyncpg - VERSION: pypy-3 FRAMEWORK: asyncpg-newest - VERSION: pypy-3 FRAMEWORK: asyncpg-0.28 + - VERSION: python-3.6 + FRAMEWORK: asyncpg-newest + - VERSION: python-3.6 + FRAMEWORK: asyncpg-0.28 - VERSION: python-3.13 FRAMEWORK: asyncpg-0.28 # sanic @@ -204,6 +259,10 @@ exclude: FRAMEWORK: sanic-newest - VERSION: pypy-3 FRAMEWORK: sanic-20.12 + - VERSION: python-3.6 + FRAMEWORK: sanic-20.12 + - VERSION: python-3.6 + FRAMEWORK: sanic-newest - VERSION: python-3.8 FRAMEWORK: sanic-newest - VERSION: python-3.13 @@ -211,13 +270,21 @@ exclude: # aioredis - VERSION: pypy-3 FRAMEWORK: aioredis-newest + - VERSION: python-3.6 + FRAMEWORK: aioredis-newest # aiomysql - VERSION: pypy-3 FRAMEWORK: aiomysql-newest + - VERSION: python-3.6 + FRAMEWORK: aiomysql-newest # aiobotocore - VERSION: pypy-3 FRAMEWORK: aiobotocore-newest + - VERSION: python-3.6 + FRAMEWORK: aiobotocore-newest # mysql-connector-python + - VERSION: python-3.6 + FRAMEWORK: mysql_connector-newest # twisted - VERSION: python-3.11 FRAMEWORK: twisted-18 @@ -251,6 +318,10 @@ exclude: - VERSION: python-3.13 FRAMEWORK: pylibmc-1.4 # grpc + - VERSION: python-3.6 + FRAMEWORK: grpc-newest + - VERSION: python-3.7 + FRAMEWORK: grpc-1.24 - VERSION: python-3.8 FRAMEWORK: grpc-1.24 - VERSION: python-3.9 @@ -263,6 +334,12 @@ exclude: FRAMEWORK: grpc-1.24 - VERSION: python-3.13 FRAMEWORK: grpc-1.24 + - VERSION: python-3.7 + FRAMEWORK: flask-1.0 + - VERSION: python-3.7 + FRAMEWORK: flask-1.1 + - VERSION: python-3.7 + FRAMEWORK: jinja2-2 # TODO py3.12 - VERSION: python-3.12 FRAMEWORK: sanic-20.12 # no wheels available yet diff --git a/.ci/.matrix_python.yml b/.ci/.matrix_python.yml index a6c1e6948..86c87ad88 100644 --- a/.ci/.matrix_python.yml +++ b/.ci/.matrix_python.yml @@ -1,3 +1,3 @@ VERSION: - - python-3.8 + - python-3.6 - python-3.13 diff --git a/.ci/.matrix_python_full.yml b/.ci/.matrix_python_full.yml index 1c8ee413a..bb763b7ca 100644 --- a/.ci/.matrix_python_full.yml +++ b/.ci/.matrix_python_full.yml @@ -1,4 +1,6 @@ VERSION: + - python-3.6 + - python-3.7 - python-3.8 - python-3.9 - python-3.10 diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index 39ef88425..3bb7a554c 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -46,7 +46,7 @@ for region in $ALL_AWS_REGIONS; do --layer-name="${FULL_LAYER_NAME}" \ --description="AWS Lambda Extension Layer for the Elastic APM Python Agent" \ --license-info="BSD-3-Clause" \ - --compatible-runtimes python3.8 python3.9 python3.10 python3.11 python3.12 python3.13\ + --compatible-runtimes python3.6 python3.7 python3.8 python3.9 python3.10 python3.11 python3.12 python3.13\ --zip-file="fileb://${zip_file}") echo "${publish_output}" > "${AWS_FOLDER}/${region}" layer_version=$(echo "${publish_output}" | jq '.Version') diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e68d173b..4fc7a275e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -114,6 +114,12 @@ jobs: fail-fast: false matrix: include: + # - version: "3.6" + # framework: "none" + # asyncio: "true" + # - version: "3.7" + # framework: none + # asyncio: true - version: "3.8" framework: none asyncio: true diff --git a/Makefile b/Makefile index 82e4d2fb4..b2d00f400 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,14 @@ flake8: test: # delete any __pycache__ folders to avoid hard-to-debug caching issues find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete - echo "Python 3.7+, with asyncio"; \ - pytest -v $(PYTEST_ARGS) --showlocals $(PYTEST_MARKER) $(PYTEST_JUNIT); \ + # pypy3 should be added to the first `if` once it supports py3.7 + if [[ "$$PYTHON_VERSION" =~ ^(3.7|3.8|3.9|3.10|3.11|3.12|3.13|nightly)$$ ]] ; then \ + echo "Python 3.7+, with asyncio"; \ + pytest -v $(PYTEST_ARGS) --showlocals $(PYTEST_MARKER) $(PYTEST_JUNIT); \ + else \ + echo "Python < 3.7, without asyncio"; \ + pytest -v $(PYTEST_ARGS) --showlocals $(PYTEST_MARKER) $(PYTEST_JUNIT) --ignore-glob='*/asyncio*/*'; \ + fi coverage: PYTEST_ARGS=--cov --cov-context=test --cov-config=setup.cfg --cov-branch coverage: export COVERAGE_FILE=.coverage.docker.$(PYTHON_FULL_VERSION).$(FRAMEWORK) diff --git a/docs/reference/run-tests-locally.md b/docs/reference/run-tests-locally.md index 689b08524..f72432d7e 100644 --- a/docs/reference/run-tests-locally.md +++ b/docs/reference/run-tests-locally.md @@ -53,7 +53,7 @@ $ ./tests/scripts/docker/run_tests.sh python-version framework-version bool: def check_python_version(self) -> None: v = tuple(map(int, platform.python_version_tuple()[:2])) - if v < (3, 8): - warnings.warn("The Elastic APM agent only supports Python 3.8+", DeprecationWarning) + if v < (3, 6): + warnings.warn("The Elastic APM agent only supports Python 3.6+", DeprecationWarning) def check_server_version( self, gte: Optional[Tuple[int, ...]] = None, lte: Optional[Tuple[int, ...]] = None diff --git a/elasticapm/instrumentation/register.py b/elasticapm/instrumentation/register.py index 3e5d82230..b37aff1e9 100644 --- a/elasticapm/instrumentation/register.py +++ b/elasticapm/instrumentation/register.py @@ -28,6 +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 sys + from elasticapm.utils.module_import import import_string _cls_register = { @@ -68,29 +70,35 @@ "elasticapm.instrumentation.packages.kafka.KafkaInstrumentation", "elasticapm.instrumentation.packages.grpc.GRPCClientInstrumentation", "elasticapm.instrumentation.packages.grpc.GRPCServerInstrumentation", - "elasticapm.instrumentation.packages.asyncio.sleep.AsyncIOSleepInstrumentation", - "elasticapm.instrumentation.packages.asyncio.aiohttp_client.AioHttpClientInstrumentation", - "elasticapm.instrumentation.packages.httpx.async.httpx.HttpxAsyncClientInstrumentation", - "elasticapm.instrumentation.packages.asyncio.elasticsearch.ElasticSearchAsyncConnection", - "elasticapm.instrumentation.packages.asyncio.elasticsearch.ElasticsearchAsyncTransportInstrumentation", - "elasticapm.instrumentation.packages.asyncio.aiopg.AioPGInstrumentation", - "elasticapm.instrumentation.packages.asyncio.asyncpg.AsyncPGInstrumentation", - "elasticapm.instrumentation.packages.tornado.TornadoRequestExecuteInstrumentation", - "elasticapm.instrumentation.packages.tornado.TornadoHandleRequestExceptionInstrumentation", - "elasticapm.instrumentation.packages.tornado.TornadoRenderInstrumentation", - "elasticapm.instrumentation.packages.httpx.async.httpcore.HTTPCoreAsyncInstrumentation", - "elasticapm.instrumentation.packages.asyncio.aioredis.RedisConnectionPoolInstrumentation", - "elasticapm.instrumentation.packages.asyncio.aioredis.RedisPipelineInstrumentation", - "elasticapm.instrumentation.packages.asyncio.aioredis.RedisConnectionInstrumentation", - "elasticapm.instrumentation.packages.asyncio.aiomysql.AioMySQLInstrumentation", - "elasticapm.instrumentation.packages.asyncio.aiobotocore.AioBotocoreInstrumentation", - "elasticapm.instrumentation.packages.asyncio.starlette.StarletteServerErrorMiddlewareInstrumentation", - "elasticapm.instrumentation.packages.asyncio.redis_asyncio.RedisAsyncioInstrumentation", - "elasticapm.instrumentation.packages.asyncio.redis_asyncio.RedisPipelineInstrumentation", - "elasticapm.instrumentation.packages.asyncio.psycopg_async.AsyncPsycopgInstrumentation", - "elasticapm.instrumentation.packages.grpc.GRPCAsyncServerInstrumentation", } +if sys.version_info >= (3, 7): + _cls_register.update( + [ + "elasticapm.instrumentation.packages.asyncio.sleep.AsyncIOSleepInstrumentation", + "elasticapm.instrumentation.packages.asyncio.aiohttp_client.AioHttpClientInstrumentation", + "elasticapm.instrumentation.packages.httpx.async.httpx.HttpxAsyncClientInstrumentation", + "elasticapm.instrumentation.packages.asyncio.elasticsearch.ElasticSearchAsyncConnection", + "elasticapm.instrumentation.packages.asyncio.elasticsearch.ElasticsearchAsyncTransportInstrumentation", + "elasticapm.instrumentation.packages.asyncio.aiopg.AioPGInstrumentation", + "elasticapm.instrumentation.packages.asyncio.asyncpg.AsyncPGInstrumentation", + "elasticapm.instrumentation.packages.tornado.TornadoRequestExecuteInstrumentation", + "elasticapm.instrumentation.packages.tornado.TornadoHandleRequestExceptionInstrumentation", + "elasticapm.instrumentation.packages.tornado.TornadoRenderInstrumentation", + "elasticapm.instrumentation.packages.httpx.async.httpcore.HTTPCoreAsyncInstrumentation", + "elasticapm.instrumentation.packages.asyncio.aioredis.RedisConnectionPoolInstrumentation", + "elasticapm.instrumentation.packages.asyncio.aioredis.RedisPipelineInstrumentation", + "elasticapm.instrumentation.packages.asyncio.aioredis.RedisConnectionInstrumentation", + "elasticapm.instrumentation.packages.asyncio.aiomysql.AioMySQLInstrumentation", + "elasticapm.instrumentation.packages.asyncio.aiobotocore.AioBotocoreInstrumentation", + "elasticapm.instrumentation.packages.asyncio.starlette.StarletteServerErrorMiddlewareInstrumentation", + "elasticapm.instrumentation.packages.asyncio.redis_asyncio.RedisAsyncioInstrumentation", + "elasticapm.instrumentation.packages.asyncio.redis_asyncio.RedisPipelineInstrumentation", + "elasticapm.instrumentation.packages.asyncio.psycopg_async.AsyncPsycopgInstrumentation", + "elasticapm.instrumentation.packages.grpc.GRPCAsyncServerInstrumentation", + ] + ) + # These instrumentations should only be enabled if we're instrumenting via the # wrapper script, which calls register_wrapper_instrumentations() below. _wrapper_register = { diff --git a/setup.cfg b/setup.cfg index 9ad206732..0a56a9b01 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,6 +15,8 @@ classifiers = Operating System :: OS Independent Topic :: Software Development Programming Language :: Python + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 @@ -31,7 +33,7 @@ project_urls = Tracker = https://github.com/elastic/apm-agent-python/issues [options] -python_requires = >=3.8, <4 +python_requires = >=3.6, <4 packages = find: include_package_data = true zip_safe = false diff --git a/tests/client/client_tests.py b/tests/client/client_tests.py index e73e726ab..e42ada12c 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 056f23548..082835be3 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 e1ff057eb..ad8bb10ca 100644 --- a/tests/client/py3_exception_tests.py +++ b/tests/client/py3_exception_tests.py @@ -38,7 +38,7 @@ # # -from unittest import mock +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 d3aaf4fe7..568cf180a 100644 --- a/tests/config/central_config_tests.py +++ b/tests/config/central_config_tests.py @@ -28,8 +28,7 @@ # 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. -from unittest import mock - +import mock import pytest diff --git a/tests/config/tests.py b/tests/config/tests.py index ba07d7795..284f5694a 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/context/test_context.py b/tests/context/test_context.py index 1bae6cb87..058d60bab 100644 --- a/tests/context/test_context.py +++ b/tests/context/test_context.py @@ -39,9 +39,21 @@ def test_execution_context_backing(): execution_context = elasticapm.context.init_execution_context() - from elasticapm.context.contextvars import ContextVarsContext + if sys.version_info[0] == 3 and sys.version_info[1] >= 7: + from elasticapm.context.contextvars import ContextVarsContext - assert isinstance(execution_context, ContextVarsContext) + assert isinstance(execution_context, ContextVarsContext) + else: + try: + import opentelemetry + + pytest.skip( + "opentelemetry installs contextvars backport, so this test isn't valid for the opentelemetry matrix" + ) + except ImportError: + pass + + assert isinstance(execution_context, ThreadLocalContext) def test_execution_context_monkeypatched(monkeypatch): diff --git a/tests/contrib/asyncio/aiohttp_web_tests.py b/tests/contrib/asyncio/aiohttp_web_tests.py index 4a63d8714..929a8e1a7 100644 --- a/tests/contrib/asyncio/aiohttp_web_tests.py +++ b/tests/contrib/asyncio/aiohttp_web_tests.py @@ -32,8 +32,7 @@ aiohttp = pytest.importorskip("aiohttp") # isort:skip -from unittest import mock - +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 4053b5d5b..38c51fa08 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 337d54942..3ce3bafed 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 cb7c53ed5..29dd61fdb 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 -from unittest import mock +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 94843a83f..72c791280 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 6464f17b7..4c3f186fc 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. -from unittest import mock +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 a54cfe75a..7ffce68cf 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 91550a59f..e2abbdcd3 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 89d33ca3b..cd6cc6d3c 100644 --- a/tests/events/tests.py +++ b/tests/events/tests.py @@ -32,9 +32,8 @@ 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 1b9119b99..a559791bf 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 9e92aa29c..da2e265ed 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 2d1dcefcc..23a8d0b2a 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 62dda0402..fbf5fa44f 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 a9c51fb34..526e5079c 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 8572bcf6a..3e6b7ed9e 100644 --- a/tests/metrics/breakdown_tests.py +++ b/tests/metrics/breakdown_tests.py @@ -28,8 +28,7 @@ # 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. -from unittest import mock - +import mock import pytest import elasticapm diff --git a/tests/processors/tests.py b/tests/processors/tests.py index 84fdfb2b9..772eccf72 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,9 +464,7 @@ 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 unittest.mock.dropper", - "elasticapm.transport", + caplog.records, "Dropped event of type transaction due to processor mock.mock.dropper", "elasticapm.transport" ) diff --git a/tests/requirements/lint-isort.txt b/tests/requirements/lint-isort.txt index 2a7924352..16ad5274c 100644 --- a/tests/requirements/lint-isort.txt +++ b/tests/requirements/lint-isort.txt @@ -1 +1,2 @@ isort +mock diff --git a/tests/requirements/reqs-base.txt b/tests/requirements/reqs-base.txt index ff6e4d24c..d1105586a 100644 --- a/tests/requirements/reqs-base.txt +++ b/tests/requirements/reqs-base.txt @@ -1,25 +1,37 @@ -pytest==7.4.0 +pytest==7.0.1 ; python_version == '3.6' +pytest==7.4.0 ; python_version > '3.6' pytest-random-order==1.1.0 pytest-django==4.4.0 -coverage==7.3.1 -pytest-cov==4.1.0 +coverage==6.2 ; python_version == '3.6' +coverage==6.3 ; python_version == '3.7' +coverage[toml]==6.3 ; python_version == '3.7' +coverage==7.3.1 ; python_version > '3.7' +pytest-cov==4.0.0 ; python_version < '3.8' +pytest-cov==4.1.0 ; python_version > '3.7' +jinja2==3.1.5 ; python_version == '3.7' pytest-localserver==0.9.0 -pytest-mock==3.10.0 -pytest-benchmark==4.0.0 -pytest-bdd==6.1.1 -pytest-rerunfailures==11.1.2 -jsonschema==4.17.3 +pytest-mock==3.6.1 ; python_version == '3.6' +pytest-mock==3.10.0 ; python_version > '3.6' +pytest-benchmark==3.4.1 ; python_version == '3.6' +pytest-benchmark==4.0.0 ; python_version > '3.6' +pytest-bdd==5.0.0 ; python_version == '3.6' +pytest-bdd==6.1.1 ; python_version > '3.6' +pytest-rerunfailures==10.2 ; python_version == '3.6' +pytest-rerunfailures==11.1.2 ; python_version > '3.6' +jsonschema==3.2.0 ; python_version == '3.6' +jsonschema==4.17.3 ; python_version > '3.6' urllib3!=2.0.0,<3.0.0 certifi Logbook +mock pytz ecs_logging structlog wrapt>=1.14.1,!=1.15.0 simplejson -pytest-asyncio==0.21.0 -asynctest==0.13.0 +pytest-asyncio==0.21.0 ; python_version >= '3.7' +asynctest==0.13.0 ; python_version >= '3.7' typing_extensions!=3.10.0.1 ; python_version >= '3.10' # see https://github.com/python/typing/issues/865 diff --git a/tests/scripts/envs/azure.sh b/tests/scripts/envs/azure.sh deleted file mode 100644 index d190b5882..000000000 --- a/tests/scripts/envs/azure.sh +++ /dev/null @@ -1 +0,0 @@ -export PYTEST_MARKER="-m azurestorage" diff --git a/tests/scripts/run_tests.sh b/tests/scripts/run_tests.sh index 414a09885..7fcc85010 100755 --- a/tests/scripts/run_tests.sh +++ b/tests/scripts/run_tests.sh @@ -6,7 +6,7 @@ export PATH=${HOME}/.local/bin:${PATH} python -m pip install --user -U pip setuptools --cache-dir "${PIP_CACHE}" python -m pip install --user -r "tests/requirements/reqs-${FRAMEWORK}.txt" --cache-dir "${PIP_CACHE}" -export PYTHON_VERSION=$(python -c "import platform; pv=platform.python_version_tuple(); print('pypy' + (str(pv[0])) if platform.python_implementation() == 'PyPy' else '.'.join(map(str, platform.python_version_tuple()[:2])))") +export PYTHON_VERSION=$(python -c "import platform; pv=platform.python_version_tuple(); print('pypy' + ('' if pv[0] == 2 else str(pv[0])) if platform.python_implementation() == 'PyPy' else '.'.join(map(str, platform.python_version_tuple()[:2])))") # check if the full FRAMEWORK name is in scripts/envs if [[ -e "./tests/scripts/envs/${FRAMEWORK}.sh" ]] diff --git a/tests/transports/test_base.py b/tests/transports/test_base.py index 37250cf7c..2f77c3e95 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 e53cb91e8..32a5b7384 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 a365c2c93..07c1f82e0 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 352d0bb48..9da7ac2f8 100644 --- a/tests/utils/compat_tests.py +++ b/tests/utils/compat_tests.py @@ -28,8 +28,7 @@ # 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. -from unittest import mock - +import mock import pytest from elasticapm.utils import compat diff --git a/tests/utils/stacks/tests.py b/tests/utils/stacks/tests.py index 6b3ba0f89..c4be88ff2 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 d9f2bf651..1c7329cd9 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