Skip to content

Commit 9561fff

Browse files
authored
Remove Python<=3.5 compatibility code from tests (#2649)
- remove py<=3.5 specific imports - remove test markers for skipping/xfailing tests on py<=3.5
1 parent 4673548 commit 9561fff

45 files changed

Lines changed: 90 additions & 381 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/conftest.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import socket
44
from threading import Thread
55
from contextlib import contextmanager
6+
from http.server import BaseHTTPRequestHandler, HTTPServer
7+
from unittest import mock
68

79
import pytest
810
import jsonschema
@@ -17,22 +19,6 @@
1719
except ImportError:
1820
eventlet = None
1921

20-
try:
21-
# Python 2
22-
import BaseHTTPServer
23-
24-
HTTPServer = BaseHTTPServer.HTTPServer
25-
BaseHTTPRequestHandler = BaseHTTPServer.BaseHTTPRequestHandler
26-
except Exception:
27-
# Python 3
28-
from http.server import BaseHTTPRequestHandler, HTTPServer
29-
30-
31-
try:
32-
from unittest import mock
33-
except ImportError:
34-
import mock
35-
3622
import sentry_sdk
3723
from sentry_sdk.envelope import Envelope
3824
from sentry_sdk.integrations import _processed_integrations # noqa: F401

tests/integrations/aiohttp/test_aiohttp.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import json
33
from contextlib import suppress
4+
from unittest import mock
45

56
import pytest
67
from aiohttp import web
@@ -10,11 +11,6 @@
1011
from sentry_sdk import capture_message, start_transaction
1112
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
1213

13-
try:
14-
from unittest import mock # python 3.3 and above
15-
except ImportError:
16-
import mock # python < 3.3
17-
1814

1915
@pytest.mark.asyncio
2016
async def test_basic(sentry_init, aiohttp_client, capture_events):

tests/integrations/asgi/test_asgi.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
from collections import Counter
42

53
import pytest
@@ -11,11 +9,6 @@
119
from async_asgi_testclient import TestClient
1210

1311

14-
minimum_python_36 = pytest.mark.skipif(
15-
sys.version_info < (3, 6), reason="ASGI is only supported in Python >= 3.6"
16-
)
17-
18-
1912
@pytest.fixture
2013
def asgi3_app():
2114
async def app(scope, receive, send):
@@ -133,7 +126,6 @@ async def app(scope, receive, send):
133126
return app
134127

135128

136-
@minimum_python_36
137129
def test_invalid_transaction_style(asgi3_app):
138130
with pytest.raises(ValueError) as exp:
139131
SentryAsgiMiddleware(asgi3_app, transaction_style="URL")
@@ -144,7 +136,6 @@ def test_invalid_transaction_style(asgi3_app):
144136
)
145137

146138

147-
@minimum_python_36
148139
@pytest.mark.asyncio
149140
async def test_capture_transaction(
150141
sentry_init,
@@ -176,7 +167,6 @@ async def test_capture_transaction(
176167
}
177168

178169

179-
@minimum_python_36
180170
@pytest.mark.asyncio
181171
async def test_capture_transaction_with_error(
182172
sentry_init,
@@ -214,7 +204,6 @@ async def test_capture_transaction_with_error(
214204
assert transaction_event["request"] == error_event["request"]
215205

216206

217-
@minimum_python_36
218207
@pytest.mark.asyncio
219208
async def test_has_trace_if_performance_enabled(
220209
sentry_init,
@@ -247,7 +236,6 @@ async def test_has_trace_if_performance_enabled(
247236
)
248237

249238

250-
@minimum_python_36
251239
@pytest.mark.asyncio
252240
async def test_has_trace_if_performance_disabled(
253241
sentry_init,
@@ -271,7 +259,6 @@ async def test_has_trace_if_performance_disabled(
271259
assert "trace_id" in error_event["contexts"]["trace"]
272260

273261

274-
@minimum_python_36
275262
@pytest.mark.asyncio
276263
async def test_trace_from_headers_if_performance_enabled(
277264
sentry_init,
@@ -305,7 +292,6 @@ async def test_trace_from_headers_if_performance_enabled(
305292
assert transaction_event["contexts"]["trace"]["trace_id"] == trace_id
306293

307294

308-
@minimum_python_36
309295
@pytest.mark.asyncio
310296
async def test_trace_from_headers_if_performance_disabled(
311297
sentry_init,
@@ -334,7 +320,6 @@ async def test_trace_from_headers_if_performance_disabled(
334320
assert error_event["contexts"]["trace"]["trace_id"] == trace_id
335321

336322

337-
@minimum_python_36
338323
@pytest.mark.asyncio
339324
async def test_websocket(sentry_init, asgi3_ws_app, capture_events, request):
340325
sentry_init(debug=True, send_default_pii=True)
@@ -367,7 +352,6 @@ async def test_websocket(sentry_init, asgi3_ws_app, capture_events, request):
367352
assert exc["value"] == "Oh no"
368353

369354

370-
@minimum_python_36
371355
@pytest.mark.asyncio
372356
async def test_auto_session_tracking_with_aggregates(
373357
sentry_init, asgi3_app, capture_envelopes
@@ -406,7 +390,6 @@ async def test_auto_session_tracking_with_aggregates(
406390
assert len(session_aggregates) == 1
407391

408392

409-
@minimum_python_36
410393
@pytest.mark.parametrize(
411394
"url,transaction_style,expected_transaction,expected_source",
412395
[
@@ -470,7 +453,6 @@ async def __call__():
470453
pass
471454

472455

473-
@minimum_python_36
474456
def test_looks_like_asgi3(asgi3_app):
475457
# branch: inspect.isclass(app)
476458
assert _looks_like_asgi3(MockAsgi3App)
@@ -487,7 +469,6 @@ def test_looks_like_asgi3(asgi3_app):
487469
assert not _looks_like_asgi3(asgi2)
488470

489471

490-
@minimum_python_36
491472
def test_get_ip_x_forwarded_for():
492473
headers = [
493474
(b"x-forwarded-for", b"8.8.8.8"),
@@ -525,7 +506,6 @@ def test_get_ip_x_forwarded_for():
525506
assert ip == "5.5.5.5"
526507

527508

528-
@minimum_python_36
529509
def test_get_ip_x_real_ip():
530510
headers = [
531511
(b"x-real-ip", b"10.10.10.10"),
@@ -550,7 +530,6 @@ def test_get_ip_x_real_ip():
550530
assert ip == "8.8.8.8"
551531

552532

553-
@minimum_python_36
554533
def test_get_ip():
555534
# if now headers are provided the ip is taken from the client.
556535
headers = []
@@ -584,7 +563,6 @@ def test_get_ip():
584563
assert ip == "10.10.10.10"
585564

586565

587-
@minimum_python_36
588566
def test_get_headers():
589567
headers = [
590568
(b"x-real-ip", b"10.10.10.10"),
@@ -602,7 +580,6 @@ def test_get_headers():
602580
}
603581

604582

605-
@minimum_python_36
606583
@pytest.mark.asyncio
607584
@pytest.mark.parametrize(
608585
"request_url,transaction_style,expected_transaction_name,expected_transaction_source",
@@ -654,7 +631,6 @@ async def test_transaction_name(
654631
)
655632

656633

657-
@minimum_python_36
658634
@pytest.mark.asyncio
659635
@pytest.mark.parametrize(
660636
"request_url, transaction_style,expected_transaction_name,expected_transaction_source",

tests/integrations/asyncio/test_asyncio_py3.py renamed to tests/integrations/asyncio/test_asyncio.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import asyncio
22
import inspect
33
import sys
4+
from unittest.mock import MagicMock, patch
45

56
import pytest
67

78
import sentry_sdk
89
from sentry_sdk.consts import OP
910
from sentry_sdk.integrations.asyncio import AsyncioIntegration, patch_asyncio
1011

11-
try:
12-
from unittest.mock import MagicMock, patch
13-
except ImportError:
14-
from mock import MagicMock, patch
15-
1612
try:
1713
from contextvars import Context, ContextVar
1814
except ImportError:

tests/integrations/aws_lambda/test_aws.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,7 @@ def test_traces_sampler_gets_correct_values_in_sampling_context(
600600
+ dedent(inspect.getsource(ObjectDescribedBy))
601601
+ dedent(
602602
"""
603-
try:
604-
from unittest import mock # python 3.3 and above
605-
except ImportError:
606-
import mock # python < 3.3
603+
from unittest import mock
607604
608605
def _safe_is_equal(x, y):
609606
# copied from conftest.py - see docstring and comments there

tests/integrations/boto3/test_s3.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import pytest
1+
from unittest import mock
22

33
import boto3
4+
import pytest
45

56
from sentry_sdk import Hub
67
from sentry_sdk.integrations.boto3 import Boto3Integration
7-
from tests.integrations.boto3.aws_mock import MockResponse
88
from tests.integrations.boto3 import read_fixture
9-
10-
try:
11-
from unittest import mock # python 3.3 and above
12-
except ImportError:
13-
import mock # python < 3.3
9+
from tests.integrations.boto3.aws_mock import MockResponse
1410

1511

1612
session = boto3.Session(

tests/integrations/celery/test_celery.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import threading
2+
from unittest import mock
23

34
import pytest
5+
from celery import Celery, VERSION
6+
from celery.bin import worker
47

58
from sentry_sdk import Hub, configure_scope, start_transaction, get_current_span
69
from sentry_sdk.integrations.celery import (
@@ -9,14 +12,6 @@
912
_wrap_apply_async,
1013
)
1114

12-
from celery import Celery, VERSION
13-
from celery.bin import worker
14-
15-
try:
16-
from unittest import mock # python 3.3 and above
17-
except ImportError:
18-
import mock # python < 3.3
19-
2015

2116
@pytest.fixture
2217
def connect_signal(request):

tests/integrations/celery/test_celery_beat_crons.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import datetime
2-
import sys
2+
from unittest import mock
3+
from unittest.mock import MagicMock
34

45
import pytest
6+
from celery.schedules import crontab, schedule
57

8+
from sentry_sdk.crons import MonitorStatus
69
from sentry_sdk.integrations.celery import (
710
_get_headers,
811
_get_humanized_interval,
@@ -12,15 +15,6 @@
1215
crons_task_failure,
1316
crons_task_retry,
1417
)
15-
from sentry_sdk.crons import MonitorStatus
16-
from celery.schedules import crontab, schedule
17-
18-
try:
19-
from unittest import mock # python 3.3 and above
20-
from unittest.mock import MagicMock
21-
except ImportError:
22-
import mock # python < 3.3
23-
from mock import MagicMock
2418

2519

2620
def test_get_headers():
@@ -378,10 +372,6 @@ def test_get_monitor_config_timezone_in_app_conf():
378372
assert monitor_config["timezone"] == "Asia/Karachi"
379373

380374

381-
@pytest.mark.skipif(
382-
sys.version_info < (3, 0),
383-
reason="no datetime.timezone for Python 2, so skipping this test.",
384-
)
385375
def test_get_monitor_config_timezone_in_celery_schedule():
386376
app = MagicMock()
387377
app.timezone = "Asia/Karachi"

tests/integrations/cloud_resource_context/test_cloud_resource_context.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import json
2+
from unittest import mock
3+
from unittest.mock import MagicMock
24

35
import pytest
46

5-
try:
6-
from unittest import mock # python 3.3 and above
7-
from unittest.mock import MagicMock
8-
except ImportError:
9-
import mock # python < 3.3
10-
from mock import MagicMock
11-
127
from sentry_sdk.integrations.cloud_resource_context import (
138
CLOUD_PLATFORM,
149
CLOUD_PROVIDER,
@@ -32,16 +27,11 @@
3227
"version": "2017-09-30",
3328
}
3429

35-
try:
36-
# Python 3
37-
AWS_EC2_EXAMPLE_IMDSv2_PAYLOAD_BYTES = bytes(
38-
json.dumps(AWS_EC2_EXAMPLE_IMDSv2_PAYLOAD), "utf-8"
39-
)
40-
except TypeError:
41-
# Python 2
42-
AWS_EC2_EXAMPLE_IMDSv2_PAYLOAD_BYTES = bytes(
43-
json.dumps(AWS_EC2_EXAMPLE_IMDSv2_PAYLOAD)
44-
).encode("utf-8")
30+
31+
AWS_EC2_EXAMPLE_IMDSv2_PAYLOAD_BYTES = bytes(
32+
json.dumps(AWS_EC2_EXAMPLE_IMDSv2_PAYLOAD), "utf-8"
33+
)
34+
4535

4636
GCP_GCE_EXAMPLE_METADATA_PLAYLOAD = {
4737
"instance": {

tests/integrations/django/asgi/test_asgi.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import json
33
import os
4+
from unittest import mock
45

56
import django
67
import pytest
@@ -14,10 +15,6 @@
1415
except ImportError:
1516
from django.core.urlresolvers import reverse
1617

17-
try:
18-
from unittest import mock # python 3.3 and above
19-
except ImportError:
20-
import mock # python < 3.3
2118

2219
APPS = [channels_application]
2320
if django.VERSION >= (3, 0):

0 commit comments

Comments
 (0)