diff --git a/example/asyncio/aioclient.py b/example/asyncio/aioclient.py
index d835c03c..fb869675 100644
--- a/example/asyncio/aioclient.py
+++ b/example/asyncio/aioclient.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2019
-from __future__ import absolute_import
-
import aiohttp
import asyncio
diff --git a/example/autoprofile/app.py b/example/autoprofile/app.py
index 3325f548..1ed9cd03 100644
--- a/example/autoprofile/app.py
+++ b/example/autoprofile/app.py
@@ -4,7 +4,6 @@
import time
import threading
import random
-import traceback
import sys
import os
@@ -13,14 +12,6 @@
os.environ['INSTANA_AUTOPROFILE'] = 'yes'
import instana
-try:
- # python 2
- from urllib2 import urlopen
-except ImportError:
- # python 3
- from urllib.request import urlopen
-
-
# Simulate CPU intensive work
def simulate_cpu():
for i in range(5000000):
diff --git a/instana/collector/base.py b/instana/collector/base.py
index bdd767e7..c1576688 100644
--- a/instana/collector/base.py
+++ b/instana/collector/base.py
@@ -13,10 +13,7 @@
from ..util import every, DictionaryOfStan
-if sys.version_info.major == 2:
- import Queue as queue
-else:
- import queue # pylint: disable=import-error
+import queue # pylint: disable=import-error
class BaseCollector(object):
diff --git a/instana/instrumentation/celery/hooks.py b/instana/instrumentation/celery/hooks.py
index e62f9b58..eb2a180c 100644
--- a/instana/instrumentation/celery/hooks.py
+++ b/instana/instrumentation/celery/hooks.py
@@ -3,6 +3,7 @@
import opentracing
+
from ...log import logger
from ...singletons import tracer
from ...util.traceutils import get_active_tracer
@@ -12,11 +13,7 @@
from celery import registry, signals
from .catalog import task_catalog_get, task_catalog_pop, task_catalog_push, get_task_id
- try:
- from urllib import parse
- except ImportError:
- import urlparse as parse
- import urllib
+ from urllib import parse
def add_broker_tags(span, broker_url):
diff --git a/instana/instrumentation/django/middleware.py b/instana/instrumentation/django/middleware.py
index d50488cc..d1485163 100644
--- a/instana/instrumentation/django/middleware.py
+++ b/instana/instrumentation/django/middleware.py
@@ -108,11 +108,7 @@ def process_exception(self, request, exception):
def __url_pattern_route(self, view_name):
from django.conf import settings
- try:
- from django.urls import RegexURLPattern as URLPattern
- from django.urls import RegexURLResolver as URLResolver
- except ImportError:
- from django.urls import URLPattern, URLResolver
+ from django.urls import RegexURLResolver as URLResolver
urlconf = __import__(settings.ROOT_URLCONF, {}, {}, [''])
diff --git a/instana/instrumentation/google/cloud/collectors.py b/instana/instrumentation/google/cloud/collectors.py
index f0fe0c83..7ec44690 100644
--- a/instana/instrumentation/google/cloud/collectors.py
+++ b/instana/instrumentation/google/cloud/collectors.py
@@ -2,13 +2,7 @@
# (c) Copyright Instana Inc. 2020
import re
-
-try:
- # Python 3
- from urllib.parse import unquote
-except ImportError:
- # Python 2
- from urllib import unquote
+from urllib.parse import unquote
# _storage_api defines a conversion of Google Storage JSON API requests into span tags as follows:
# request_method -> path_matcher -> collector
diff --git a/instana/propagators/base_propagator.py b/instana/propagators/base_propagator.py
index 876b271a..a70d032d 100644
--- a/instana/propagators/base_propagator.py
+++ b/instana/propagators/base_propagator.py
@@ -3,16 +3,13 @@
import sys
+import os
from instana.log import logger
from instana.util.ids import header_to_id, header_to_long_id
from instana.span_context import SpanContext
from instana.w3c_trace_context.traceparent import Traceparent
from instana.w3c_trace_context.tracestate import Tracestate
-import os
-
-PY2 = sys.version_info[0] == 2
-PY3 = sys.version_info[0] == 3
# The carrier can be a dict or a list.
@@ -233,7 +230,7 @@ def __extract_instana_headers(self, dc):
level = dc.get(self.LC_HEADER_KEY_L) or dc.get(self.ALT_LC_HEADER_KEY_L) or dc.get(
self.B_HEADER_KEY_L) or dc.get(self.B_ALT_LC_HEADER_KEY_L)
- if level and PY3 is True and isinstance(level, bytes):
+ if level and isinstance(level, bytes):
level = level.decode("utf-8")
synthetic = dc.get(self.LC_HEADER_KEY_SYNTHETIC) or dc.get(self.ALT_LC_HEADER_KEY_SYNTHETIC) or dc.get(
@@ -258,12 +255,12 @@ def __extract_w3c_trace_context_headers(self, dc):
try:
traceparent = dc.get(self.HEADER_KEY_TRACEPARENT) or dc.get(self.ALT_HEADER_KEY_TRACEPARENT) or dc.get(
self.B_HEADER_KEY_TRACEPARENT) or dc.get(self.B_ALT_HEADER_KEY_TRACEPARENT)
- if traceparent and PY3 is True and isinstance(traceparent, bytes):
+ if traceparent and isinstance(traceparent, bytes):
traceparent = traceparent.decode("utf-8")
tracestate = dc.get(self.HEADER_KEY_TRACESTATE) or dc.get(self.ALT_HEADER_KEY_TRACESTATE) or dc.get(
self.B_HEADER_KEY_TRACESTATE) or dc.get(self.B_ALT_HEADER_KEY_TRACESTATE)
- if tracestate and PY3 is True and isinstance(tracestate, bytes):
+ if tracestate and isinstance(tracestate, bytes):
tracestate = tracestate.decode("utf-8")
except Exception:
diff --git a/instana/recorder.py b/instana/recorder.py
index d5d0d714..b5875805 100644
--- a/instana/recorder.py
+++ b/instana/recorder.py
@@ -21,8 +21,8 @@ class StanRecorder(object):
"couchbase", "django", "gcs", "gcps-producer",
"gcps-consumer", "log", "memcache", "mongo", "mysql",
"postgres", "pymongo", "rabbitmq", "redis","render",
- "rpc-client", "rpc-server", "sqlalchemy", "soap",
- "tornado-client", "tornado-server", "urllib3", "wsgi", "asgi")
+ "rpc-client", "rpc-server", "sqlalchemy", "tornado-client",
+ "tornado-server", "urllib3", "wsgi", "asgi")
# Recorder thread for collection/reporting of spans
thread = None
diff --git a/instana/span.py b/instana/span.py
index dac66d32..5398fbd3 100644
--- a/instana/span.py
+++ b/instana/span.py
@@ -245,12 +245,12 @@ def get_span_kind(self, span):
class RegisteredSpan(BaseSpan):
- HTTP_SPANS = ("aiohttp-client", "aiohttp-server", "django", "http", "soap", "tornado-client",
+ HTTP_SPANS = ("aiohttp-client", "aiohttp-server", "django", "http", "tornado-client",
"tornado-server", "urllib3", "wsgi", "asgi")
EXIT_SPANS = ("aiohttp-client", "boto3", "cassandra", "celery-client", "couchbase", "log", "memcache",
"mongo", "mysql", "postgres", "rabbitmq", "redis", "rpc-client", "sqlalchemy",
- "soap", "tornado-client", "urllib3", "pymongo", "gcs", "gcps-producer")
+ "tornado-client", "urllib3", "pymongo", "gcs", "gcps-producer")
ENTRY_SPANS = ("aiohttp-server", "aws.lambda.entry", "celery-worker", "django", "wsgi", "rabbitmq",
"rpc-server", "tornado-server", "gcps-consumer", "asgi")
@@ -501,9 +501,6 @@ def _collect_http_tags(self, span):
self.data["http"]["error"] = span.tags.pop('http.error', None)
if len(span.tags) > 0:
- if span.operation_name == "soap":
- self.data["soap"]["action"] = span.tags.pop('soap.action', None)
-
custom_headers = []
for key in span.tags:
if key[0:12] == "http.header.":
diff --git a/instana/util/__init__.py b/instana/util/__init__.py
index ff6993df..94c79646 100644
--- a/instana/util/__init__.py
+++ b/instana/util/__init__.py
@@ -2,28 +2,14 @@
# (c) Copyright Instana Inc. 2020
import json
-import sys
import time
-
from collections import defaultdict
-import pkg_resources
+from urllib import parse
-try:
- from urllib import parse
-except ImportError:
- import urlparse as parse
- import urllib
+import pkg_resources
from ..log import logger
-if sys.version_info.major == 2:
- string_types = basestring
-else:
- string_types = str
-
-PY2 = sys.version_info[0] == 2
-PY3 = sys.version_info[0] == 3
-
def nested_dictionary():
return defaultdict(DictionaryOfStan)
diff --git a/instana/util/ids.py b/instana/util/ids.py
index 4449916b..3d6e8d01 100644
--- a/instana/util/ids.py
+++ b/instana/util/ids.py
@@ -2,7 +2,6 @@
# (c) Copyright Instana Inc. 2020
import os
-import sys
import time
import random
@@ -11,14 +10,6 @@
BAD_ID = "BADCAFFE" # Bad Caffe
-PY2 = sys.version_info[0] == 2
-PY3 = sys.version_info[0] == 3
-
-if PY2:
- string_types = basestring
-else:
- string_types = str
-
def generate_id():
""" Generate a 64bit base 16 ID for use as a Span or Trace ID """
@@ -45,10 +36,10 @@ def header_to_long_id(header):
:param header: the header to analyze, validate and convert (if needed)
:return: a valid ID to be used internal to the tracer
"""
- if PY3 is True and isinstance(header, bytes):
+ if isinstance(header, bytes):
header = header.decode('utf-8')
- if not isinstance(header, string_types):
+ if not isinstance(header, str):
return BAD_ID
try:
@@ -74,10 +65,10 @@ def header_to_id(header):
:param header: the header to analyze, validate and convert (if needed)
:return: a valid ID to be used internal to the tracer
"""
- if PY3 is True and isinstance(header, bytes):
+ if isinstance(header, bytes):
header = header.decode('utf-8')
- if not isinstance(header, string_types):
+ if not isinstance(header, str):
return BAD_ID
try:
diff --git a/instana/util/secrets.py b/instana/util/secrets.py
index 1cb835c5..f5b8c071 100644
--- a/instana/util/secrets.py
+++ b/instana/util/secrets.py
@@ -2,16 +2,8 @@
# (c) Copyright Instana Inc. 2020
import re
-import re
-import sys
-
-try:
- from urllib import parse
-except ImportError:
- import urlparse as parse
- import urllib
+from urllib import parse
-from ..util import PY2, PY3
from ..log import logger
@@ -127,10 +119,7 @@ def strip_secrets_from_query(qp, matcher, kwlist):
logger.debug("strip_secrets_from_query: unknown matcher")
return qp
- if PY2:
- result = urllib.urlencode(params, doseq=True)
- else:
- result = parse.urlencode(params, doseq=True)
+ result = parse.urlencode(params, doseq=True)
query = parse.unquote(result)
if path:
diff --git a/tests/__init__.py b/tests/__init__.py
index 0ae58430..7aad59cd 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,7 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2017
-from __future__ import absolute_import
import os
os.environ["INSTANA_TEST"] = "true"
diff --git a/tests/apps/grpc_server/stan_client.py b/tests/apps/grpc_server/stan_client.py
index 69a69c90..450d62eb 100644
--- a/tests/apps/grpc_server/stan_client.py
+++ b/tests/apps/grpc_server/stan_client.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2019
-from __future__ import absolute_import
-
import time
import random
diff --git a/tests/apps/soap_app/__init__.py b/tests/apps/soap_app/__init__.py
deleted file mode 100644
index 4bf816f1..00000000
--- a/tests/apps/soap_app/__init__.py
+++ /dev/null
@@ -1,12 +0,0 @@
-# (c) Copyright IBM Corp. 2021
-# (c) Copyright Instana Inc. 2020
-
-import sys
-from .app import soapserver as server
-from ..utils import launch_background_thread
-
-app_thread = None
-
-if sys.version_info < (3, 7, 0) and app_thread is None:
- app_thread = launch_background_thread(server.serve_forever, "SoapServer")
-
diff --git a/tests/apps/soap_app/app.py b/tests/apps/soap_app/app.py
deleted file mode 100644
index 284cc4ee..00000000
--- a/tests/apps/soap_app/app.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env python
-# (c) Copyright IBM Corp. 2021
-# (c) Copyright Instana Inc. 2020
-
-# -*- coding: utf-8 -*-
-import logging
-
-from spyne.protocol.soap import Soap11
-from spyne.server.wsgi import WsgiApplication
-from wsgiref.simple_server import make_server
-from spyne import (Application, Fault, Integer, Iterable, ServiceBase, Unicode, rpc)
-
-from ...helpers import testenv
-from instana.wsgi import iWSGIMiddleware
-
-
-testenv["soap_port"] = 10812
-testenv["soap_server"] = ("http://127.0.0.1:" + str(testenv["soap_port"]))
-
-
-# Simple in test suite SOAP server to test suds client instrumentation against.
-# Configured to listen on localhost port 4132
-# WSDL: http://localhost:4232/?wsdl
-class StanSoapService(ServiceBase):
- @rpc(Unicode, Integer, _returns=Iterable(Unicode))
- def ask_question(ctx, question, answer):
- """Ask Stan a question!
- Ask Stan questions as a Service
-
- @param name the name to say hello to
- @param times the number of times to say hello
- @return the completed array
- """
-
- yield u'To an artificial mind, all reality is virtual. How do they know that the real world isn\'t just another simulation? How do you?'
-
- @rpc()
- def server_exception(ctx):
- raise Exception("Server side exception example.")
-
- @rpc()
- def server_fault(ctx):
- raise Fault("Server", "Server side fault example.")
-
- @rpc()
- def client_fault(ctx):
- raise Fault("Client", "Client side fault example")
-
-
-# logging.basicConfig(level=logging.WARN)
-logging.getLogger('suds').setLevel(logging.WARN)
-logging.getLogger('suds.resolver').setLevel(logging.WARN)
-logging.getLogger('spyne.protocol.xml').setLevel(logging.WARN)
-logging.getLogger('spyne.model.complex').setLevel(logging.WARN)
-logging.getLogger('spyne.interface._base').setLevel(logging.WARN)
-logging.getLogger('spyne.interface.xml').setLevel(logging.WARN)
-logging.getLogger('spyne.util.appreg').setLevel(logging.WARN)
-
-app = Application([StanSoapService], 'instana.tests.app.ask_question',
- in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
-
-# Use Instana middleware so we can test context passing and Soap server traces.
-wsgi_app = iWSGIMiddleware(WsgiApplication(app))
-soapserver = make_server('127.0.0.1', testenv["soap_port"], wsgi_app)
-
-if __name__ == '__main__':
- soapserver.serve_forever()
diff --git a/tests/clients/boto3/test_boto3_lambda.py b/tests/clients/boto3/test_boto3_lambda.py
index bc9cc0cd..b7ad6082 100644
--- a/tests/clients/boto3/test_boto3_lambda.py
+++ b/tests/clients/boto3/test_boto3_lambda.py
@@ -1,7 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
import unittest
import json
diff --git a/tests/clients/boto3/test_boto3_s3.py b/tests/clients/boto3/test_boto3_s3.py
index 98a32455..36535267 100644
--- a/tests/clients/boto3/test_boto3_s3.py
+++ b/tests/clients/boto3/test_boto3_s3.py
@@ -1,7 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
import os
import unittest
diff --git a/tests/clients/boto3/test_boto3_secretsmanager.py b/tests/clients/boto3/test_boto3_secretsmanager.py
index 2edd0219..6c71ab1d 100644
--- a/tests/clients/boto3/test_boto3_secretsmanager.py
+++ b/tests/clients/boto3/test_boto3_secretsmanager.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
import boto3
import unittest
diff --git a/tests/clients/boto3/test_boto3_ses.py b/tests/clients/boto3/test_boto3_ses.py
index 23e0a2a7..2bbbcce3 100644
--- a/tests/clients/boto3/test_boto3_ses.py
+++ b/tests/clients/boto3/test_boto3_ses.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
import boto3
import unittest
diff --git a/tests/clients/boto3/test_boto3_sqs.py b/tests/clients/boto3/test_boto3_sqs.py
index f800f72a..75a9b2e3 100644
--- a/tests/clients/boto3/test_boto3_sqs.py
+++ b/tests/clients/boto3/test_boto3_sqs.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
import boto3
import unittest
diff --git a/tests/clients/test_cassandra-driver.py b/tests/clients/test_cassandra-driver.py
index a819c4ba..164d8227 100644
--- a/tests/clients/test_cassandra-driver.py
+++ b/tests/clients/test_cassandra-driver.py
@@ -1,11 +1,8 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
import time
-import pytest
import random
import unittest
@@ -31,7 +28,7 @@
");")
-@pytest.mark.skipif(not os.environ.get("CASSANDRA_TEST"), reason="")
+@unittest.skipUnless(os.environ.get("CASSANDRA_TEST"), reason="")
class TestCassandra(unittest.TestCase):
def setUp(self):
""" Clear all spans before a test run """
diff --git a/tests/clients/test_couchbase.py b/tests/clients/test_couchbase.py
index 62e9876e..0f12baa0 100644
--- a/tests/clients/test_couchbase.py
+++ b/tests/clients/test_couchbase.py
@@ -1,11 +1,8 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
import time
-import pytest
import unittest
from instana.singletons import tracer
@@ -29,7 +26,7 @@
pass
-@pytest.mark.skipif(not os.environ.get("COUCHBASE_TEST"), reason="")
+@unittest.skipIf(not os.environ.get("COUCHBASE_TEST"), reason="")
class TestStandardCouchDB(unittest.TestCase):
def setup_class(self):
""" Clear all spans before a test run """
diff --git a/tests/clients/test_google-cloud-pubsub.py b/tests/clients/test_google-cloud-pubsub.py
index 97ef9b1d..d0a8c5af 100644
--- a/tests/clients/test_google-cloud-pubsub.py
+++ b/tests/clients/test_google-cloud-pubsub.py
@@ -1,14 +1,9 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021
-from __future__ import absolute_import
-
import os
-import sys
import threading
import time
-import pytest
-
import six
import unittest
diff --git a/tests/clients/test_google-cloud-storage.py b/tests/clients/test_google-cloud-storage.py
index 6e7a5437..1af34336 100644
--- a/tests/clients/test_google-cloud-storage.py
+++ b/tests/clients/test_google-cloud-storage.py
@@ -1,11 +1,8 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import sys
import unittest
-import pytest
import json
import requests
import io
@@ -24,7 +21,7 @@ def setUp(self):
self.recorder = tracer.recorder
self.recorder.clear_spans()
- @pytest.mark.skipif(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
+ @unittest.skipIf(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
@patch('requests.Session.request')
def test_buckets_list(self, mock_requests):
mock_requests.return_value = self._mock_response(
@@ -513,7 +510,7 @@ def test_objects_insert(self, mock_requests):
self.assertEqual('test bucket', gcs_span.data["gcs"]["bucket"])
self.assertEqual('test object', gcs_span.data["gcs"]["object"])
- @pytest.mark.skipif(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
+ @unittest.skipIf(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
@patch('requests.Session.request')
def test_objects_list(self, mock_requests):
mock_requests.return_value = self._mock_response(
@@ -787,7 +784,7 @@ def test_object_hmac_keys_get(self, mock_requests):
self.assertEqual('test-project', gcs_span.data["gcs"]["projectId"])
self.assertEqual('test key', gcs_span.data["gcs"]["accessId"])
- @pytest.mark.skipif(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
+ @unittest.skipIf(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
@patch('requests.Session.request')
def test_object_hmac_keys_list(self, mock_requests):
mock_requests.return_value = self._mock_response(
diff --git a/tests/clients/test_logging.py b/tests/clients/test_logging.py
index caf08ef7..c60e8d92 100644
--- a/tests/clients/test_logging.py
+++ b/tests/clients/test_logging.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import logging
import unittest
from instana.singletons import tracer
diff --git a/tests/clients/test_mysqlclient.py b/tests/clients/test_mysqlclient.py
index 707b98d0..c1864ec7 100644
--- a/tests/clients/test_mysqlclient.py
+++ b/tests/clients/test_mysqlclient.py
@@ -1,14 +1,12 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
-import sys
import logging
import unittest
+
import MySQLdb
+
from ..helpers import testenv
-from unittest import SkipTest
from instana.singletons import tracer
logger = logging.getLogger(__name__)
diff --git a/tests/clients/test_pika.py b/tests/clients/test_pika.py
index 11dadacb..47209495 100644
--- a/tests/clients/test_pika.py
+++ b/tests/clients/test_pika.py
@@ -1,14 +1,13 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021
-from __future__ import absolute_import
-
-import pika
import unittest
-import mock
import threading
import time
+import pika
+import mock
+
from instana.singletons import tracer
diff --git a/tests/clients/test_psycopg2.py b/tests/clients/test_psycopg2.py
index fe3820c8..4754dc46 100644
--- a/tests/clients/test_psycopg2.py
+++ b/tests/clients/test_psycopg2.py
@@ -1,10 +1,9 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import logging
import unittest
+
from ..helpers import testenv
from instana.singletons import tracer
diff --git a/tests/clients/test_pymongo.py b/tests/clients/test_pymongo.py
index 6a691382..8bb13997 100644
--- a/tests/clients/test_pymongo.py
+++ b/tests/clients/test_pymongo.py
@@ -1,12 +1,9 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import json
import unittest
import logging
-import pytest
from ..helpers import testenv
from instana.singletons import tracer
@@ -16,7 +13,7 @@
logger = logging.getLogger(__name__)
-pymongoversion = pytest.mark.skipif(
+pymongoversion = unittest.skipIf(
pymongo.version_tuple >= (4, 0), reason="map reduce is removed in pymongo 4.0"
)
diff --git a/tests/clients/test_pymysql.py b/tests/clients/test_pymysql.py
index e80f3ade..c7352288 100644
--- a/tests/clients/test_pymysql.py
+++ b/tests/clients/test_pymysql.py
@@ -1,12 +1,11 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
-import sys
import logging
import unittest
+
import pymysql
+
from ..helpers import testenv
from instana.singletons import tracer
diff --git a/tests/clients/test_redis.py b/tests/clients/test_redis.py
index 4d988eeb..3090bd43 100644
--- a/tests/clients/test_redis.py
+++ b/tests/clients/test_redis.py
@@ -1,13 +1,12 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import unittest
import redis
-from ..helpers import testenv
from redis.sentinel import Sentinel
+
+from ..helpers import testenv
from instana.singletons import tracer
diff --git a/tests/clients/test_sqlalchemy.py b/tests/clients/test_sqlalchemy.py
index b05466af..38079695 100644
--- a/tests/clients/test_sqlalchemy.py
+++ b/tests/clients/test_sqlalchemy.py
@@ -1,12 +1,11 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import unittest
from ..helpers import testenv
from instana.singletons import tracer
+
from sqlalchemy.orm import sessionmaker
from sqlalchemy.exc import OperationalError
from sqlalchemy.orm import declarative_base
diff --git a/tests/clients/test_urllib3.py b/tests/clients/test_urllib3.py
index b142e65c..1644ba82 100644
--- a/tests/clients/test_urllib3.py
+++ b/tests/clients/test_urllib3.py
@@ -1,7 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
from multiprocessing.pool import ThreadPool
from time import sleep
import unittest
diff --git a/tests/conftest.py b/tests/conftest.py
index e913b5a2..4269493c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -27,13 +27,13 @@
# Python 3.10 support is incomplete yet
# TODO: Remove this once we start supporting Tornado >= 6.0
-if sys.version_info.minor >= 10:
+if sys.version_info >= (3, 10):
collect_ignore_glob.append("*test_tornado*")
# Furthermore on Python 3.11 the above TC is skipped:
# tests/opentracing/test_ot_span.py::TestOTSpan::test_stacks
# TODO: Remove that once we find a workaround or DROP opentracing!
-if sys.version_info.minor >= 12:
+if sys.version_info >= (3, 12):
# Currently the dependencies of sanic and aiohttp are not installable on 3.12
# PyLongObject’ {aka ‘struct _longobject’} has no member named ‘ob_digit’
collect_ignore_glob.append("*test_sanic*")
diff --git a/tests/frameworks/test_aiohttp_client.py b/tests/frameworks/test_aiohttp_client.py
index 1076c3db..20f82130 100644
--- a/tests/frameworks/test_aiohttp_client.py
+++ b/tests/frameworks/test_aiohttp_client.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import aiohttp
import asyncio
import unittest
diff --git a/tests/frameworks/test_aiohttp_server.py b/tests/frameworks/test_aiohttp_server.py
index d1c7dfd9..9c5127ae 100644
--- a/tests/frameworks/test_aiohttp_server.py
+++ b/tests/frameworks/test_aiohttp_server.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import aiohttp
import asyncio
import unittest
diff --git a/tests/frameworks/test_asyncio.py b/tests/frameworks/test_asyncio.py
index 21b22d6e..73bcf95b 100644
--- a/tests/frameworks/test_asyncio.py
+++ b/tests/frameworks/test_asyncio.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import asyncio
import aiohttp
import unittest
diff --git a/tests/frameworks/test_celery.py b/tests/frameworks/test_celery.py
index 36aed7b8..bd08877f 100644
--- a/tests/frameworks/test_celery.py
+++ b/tests/frameworks/test_celery.py
@@ -1,10 +1,10 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import time
+
from celery import shared_task
+
from instana.singletons import tracer
from ..helpers import get_first_span_by_filter
diff --git a/tests/frameworks/test_django.py b/tests/frameworks/test_django.py
index 9a471faa..02778efc 100644
--- a/tests/frameworks/test_django.py
+++ b/tests/frameworks/test_django.py
@@ -1,7 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
import os
import urllib3
diff --git a/tests/frameworks/test_fastapi.py b/tests/frameworks/test_fastapi.py
index e4710008..cafbd8c1 100644
--- a/tests/frameworks/test_fastapi.py
+++ b/tests/frameworks/test_fastapi.py
@@ -1,7 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
import time
import unittest
import multiprocessing
diff --git a/tests/frameworks/test_flask.py b/tests/frameworks/test_flask.py
index 78c43512..65bf0ea7 100644
--- a/tests/frameworks/test_flask.py
+++ b/tests/frameworks/test_flask.py
@@ -1,9 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
-import sys
import unittest
import urllib3
import flask
@@ -715,10 +712,7 @@ def test_exception(self):
# error log
self.assertEqual("log", log_span.n)
self.assertEqual('Exception on /exception [GET]', log_span.data["log"]['message'])
- if sys.version_info < (3, 0):
- self.assertEqual(" fake error", log_span.data["log"]['parameters'])
- else:
- self.assertEqual(" fake error", log_span.data["log"]['parameters'])
+ self.assertEqual(" fake error", log_span.data["log"]['parameters'])
# wsgis
diff --git a/tests/frameworks/test_gevent.py b/tests/frameworks/test_gevent.py
index d5d94fe0..022309ce 100644
--- a/tests/frameworks/test_gevent.py
+++ b/tests/frameworks/test_gevent.py
@@ -1,23 +1,21 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
-import pytest
+import unittest
+
import gevent
from gevent.pool import Group
import urllib3
-import unittest
+from opentracing.scope_managers.gevent import GeventScopeManager
import tests.apps.flask_app
from instana.span import SDKSpan
from instana.singletons import tracer
from ..helpers import testenv, get_spans_by_filter
-from opentracing.scope_managers.gevent import GeventScopeManager
-@pytest.mark.skipif(not os.environ.get("GEVENT_TEST"), reason="")
+@unittest.skipIf(not os.environ.get("GEVENT_TEST"), reason="")
class TestGEvent(unittest.TestCase):
def setUp(self):
self.http = urllib3.HTTPConnectionPool('127.0.0.1', port=testenv["wsgi_port"], maxsize=20)
diff --git a/tests/frameworks/test_grpcio.py b/tests/frameworks/test_grpcio.py
index c100b111..09572a5e 100644
--- a/tests/frameworks/test_grpcio.py
+++ b/tests/frameworks/test_grpcio.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import time
import unittest
import random
diff --git a/tests/frameworks/test_pyramid.py b/tests/frameworks/test_pyramid.py
index 8fe6cc62..f3f88fb0 100644
--- a/tests/frameworks/test_pyramid.py
+++ b/tests/frameworks/test_pyramid.py
@@ -1,7 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
import unittest
import urllib3
diff --git a/tests/frameworks/test_sanic.py b/tests/frameworks/test_sanic.py
index 884d1280..6cea3549 100644
--- a/tests/frameworks/test_sanic.py
+++ b/tests/frameworks/test_sanic.py
@@ -1,24 +1,18 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021
-from __future__ import absolute_import
-
import time
-import pytest
import requests
import multiprocessing
+import unittest
+
from instana.singletons import tracer
from ..helpers import testenv
from ..helpers import get_first_span_by_filter
from ..test_utils import _TraceContextMixin
-import sys
-import unittest
-@pytest.mark.skipif(sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 7),
- reason="testing sanic for python 3.7 and up")
class TestSanic(unittest.TestCase, _TraceContextMixin):
-
def setUp(self):
from tests.apps.sanic_app import launch_sanic
self.proc = multiprocessing.Process(target=launch_sanic, args=(), daemon=True)
@@ -26,6 +20,7 @@ def setUp(self):
time.sleep(2)
def tearDown(self):
+ """ Kill server after tests """
self.proc.kill()
def test_vanilla_get(self):
diff --git a/tests/frameworks/test_starlette.py b/tests/frameworks/test_starlette.py
index 72736e84..6df31c99 100644
--- a/tests/frameworks/test_starlette.py
+++ b/tests/frameworks/test_starlette.py
@@ -1,12 +1,11 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import time
import pytest
import requests
import multiprocessing
+
from ..helpers import testenv
from instana.singletons import tracer
from ..helpers import get_first_span_by_filter
diff --git a/tests/frameworks/test_tornado_client.py b/tests/frameworks/test_tornado_client.py
index 20a2392c..2980f226 100644
--- a/tests/frameworks/test_tornado_client.py
+++ b/tests/frameworks/test_tornado_client.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import time
import asyncio
import unittest
diff --git a/tests/frameworks/test_tornado_server.py b/tests/frameworks/test_tornado_server.py
index f5ffc7c4..5deaae46 100644
--- a/tests/frameworks/test_tornado_server.py
+++ b/tests/frameworks/test_tornado_server.py
@@ -1,13 +1,10 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
+import unittest
-import time
import asyncio
import aiohttp
-import unittest
-
import tornado
from tornado.httpclient import AsyncHTTPClient
diff --git a/tests/frameworks/test_wsgi.py b/tests/frameworks/test_wsgi.py
index def7709b..25dbaa5a 100644
--- a/tests/frameworks/test_wsgi.py
+++ b/tests/frameworks/test_wsgi.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import time
import urllib3
import unittest
diff --git a/tests/opentracing/test_ot_span.py b/tests/opentracing/test_ot_span.py
index bcdccf9b..0196aa0c 100644
--- a/tests/opentracing/test_ot_span.py
+++ b/tests/opentracing/test_ot_span.py
@@ -6,16 +6,14 @@
import json
import time
import unittest
-import pytest
-import opentracing
from uuid import UUID
+
+import opentracing
+
from instana.util import to_json
from instana.singletons import agent, tracer
from ..helpers import get_first_span_by_filter
-PY2 = sys.version_info[0] == 2
-PY3 = sys.version_info[0] == 3
-
class TestOTSpan(unittest.TestCase):
def setUp(self):
@@ -51,7 +49,7 @@ def test_span_ids(self):
# Python 3.11 support is incomplete yet
# TODO: Remove this once we find a workaround or DROP opentracing!
- @pytest.mark.skipif(sys.version_info.minor >= 11, reason="Raises not Implemented exception in OSX")
+ @unittest.skipIf(sys.version_info >= (3, 11), reason="Raises not Implemented exception in OSX")
def test_stacks(self):
# Entry spans have no stack attached by default
wsgi_span = opentracing.tracer.start_span("wsgi")
@@ -76,7 +74,7 @@ def test_span_fields(self):
self.assertEqual("string", span.tags['tagone'])
self.assertEqual(150, span.tags['tagtwo'])
- @pytest.mark.skipif(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
+ @unittest.skipIf(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
def test_span_queueing(self):
recorder = opentracing.tracer.recorder
@@ -196,12 +194,8 @@ def test_tag_values(self):
assert(test_span.data['sdk']['custom']['tags']['tracer'])
assert(test_span.data['sdk']['custom']['tags']['none'] == 'None')
assert(test_span.data['sdk']['custom']['tags']['mylist'] == [1, 2, 3])
- if PY2:
- set_regexp = re.compile(r"set\(\[.*,.*\]\)")
- assert(set_regexp.search(test_span.data['sdk']['custom']['tags']['myset']))
- else:
- set_regexp = re.compile(r"\{.*,.*\}")
- assert(set_regexp.search(test_span.data['sdk']['custom']['tags']['myset']))
+ set_regexp = re.compile(r"\{.*,.*\}")
+ assert(set_regexp.search(test_span.data['sdk']['custom']['tags']['myset']))
# Convert to JSON
json_data = to_json(test_span)
@@ -214,12 +208,8 @@ def test_tag_values(self):
assert(span_dict['data']['sdk']['custom']['tags']['tracer'])
assert(span_dict['data']['sdk']['custom']['tags']['none'] == 'None')
assert(span_dict['data']['sdk']['custom']['tags']['mylist'] == [1, 2, 3])
- if PY2:
- set_regexp = re.compile(r"set\(\[.*,.*\]\)")
- assert(set_regexp.search(test_span.data['sdk']['custom']['tags']['myset']))
- else:
- set_regexp = re.compile(r"{.*,.*}")
- assert(set_regexp.search(test_span.data['sdk']['custom']['tags']['myset']))
+ set_regexp = re.compile(r"{.*,.*}")
+ assert(set_regexp.search(test_span.data['sdk']['custom']['tags']['myset']))
def test_tag_names(self):
with tracer.start_active_span('test') as scope:
diff --git a/tests/platforms/test_fargate.py b/tests/platforms/test_fargate.py
index 9302f5b3..7a50353a 100644
--- a/tests/platforms/test_fargate.py
+++ b/tests/platforms/test_fargate.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
import logging
import unittest
diff --git a/tests/platforms/test_fargate_collector.py b/tests/platforms/test_fargate_collector.py
index 90993e22..361d14e8 100644
--- a/tests/platforms/test_fargate_collector.py
+++ b/tests/platforms/test_fargate_collector.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
import json
import unittest
diff --git a/tests/platforms/test_gcr_collector.py b/tests/platforms/test_gcr_collector.py
index 4e828f3d..39c7e886 100644
--- a/tests/platforms/test_gcr_collector.py
+++ b/tests/platforms/test_gcr_collector.py
@@ -1,13 +1,12 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021
-from __future__ import absolute_import
-
import os
import json
-import requests_mock
import unittest
+import requests_mock
+
from instana.tracer import InstanaTracer
from instana.recorder import StanRecorder
from instana.agent.google_cloud_run import GCRAgent
diff --git a/tests/platforms/test_google_cloud_run.py b/tests/platforms/test_google_cloud_run.py
index 4cc95202..8b086a70 100644
--- a/tests/platforms/test_google_cloud_run.py
+++ b/tests/platforms/test_google_cloud_run.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021
-from __future__ import absolute_import
-
import os
import logging
import unittest
diff --git a/tests/platforms/test_host.py b/tests/platforms/test_host.py
index 937d76c4..2ca09804 100644
--- a/tests/platforms/test_host.py
+++ b/tests/platforms/test_host.py
@@ -1,14 +1,11 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
import logging
import unittest
from mock import MagicMock, patch
-
import requests
from instana.agent.host import HostAgent
diff --git a/tests/platforms/test_host_collector.py b/tests/platforms/test_host_collector.py
index 1f6b19fa..1a21b1fb 100644
--- a/tests/platforms/test_host_collector.py
+++ b/tests/platforms/test_host_collector.py
@@ -1,13 +1,10 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
-import json
import unittest
import sys
-import mock
+
from mock import patch
from instana.tracer import InstanaTracer
diff --git a/tests/platforms/test_lambda.py b/tests/platforms/test_lambda.py
index 4ad8f0f8..c330b3a7 100644
--- a/tests/platforms/test_lambda.py
+++ b/tests/platforms/test_lambda.py
@@ -1,16 +1,14 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
import os
-import sys
import json
import time
-import wrapt
import logging
import unittest
+import wrapt
+
from instana.tracer import InstanaTracer
from instana.agent.aws_lambda import AWSLambdaAgent
from instana.options import AWSLambdaOptions
diff --git a/tests/test_configurator.py b/tests/test_configurator.py
index 120ae16d..a95ee13d 100644
--- a/tests/test_configurator.py
+++ b/tests/test_configurator.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2019
-from __future__ import absolute_import
-
import unittest
from instana.configurator import config
diff --git a/tests/test_id_management.py b/tests/test_id_management.py
index 69412e44..61ba5ad3 100644
--- a/tests/test_id_management.py
+++ b/tests/test_id_management.py
@@ -1,15 +1,8 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2017
-import sys
-import string
import instana
-if sys.version_info.major == 2:
- string_types = basestring
-else:
- string_types = str
-
def test_id_generation():
count = 0
diff --git a/tests/test_secrets.py b/tests/test_secrets.py
index 4e920795..04346e85 100644
--- a/tests/test_secrets.py
+++ b/tests/test_secrets.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2018
-from __future__ import absolute_import
-
import unittest
from instana.util.secrets import strip_secrets_from_query
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 569de0a0..43943695 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,8 +1,6 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020
-from __future__ import absolute_import
-
from instana.util import validate_url