Skip to content

Commit 963e0d5

Browse files
authored
Move importorskips in tests to __init__.py files (#2412)
Let's make the placement of the `importorskip`s consistent.
1 parent fb39f22 commit 963e0d5

Some content is hidden

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

42 files changed

+63
-58
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
aiohttp = pytest.importorskip("aiohttp")
3+
pytest.importorskip("aiohttp")
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pytest
2+
3+
pytest.importorskip("ariadne")
4+
pytest.importorskip("fastapi")
5+
pytest.importorskip("flask")

tests/integrations/ariadne/test_ariadne.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import pytest
2-
3-
pytest.importorskip("ariadne")
4-
pytest.importorskip("fastapi")
5-
pytest.importorskip("flask")
6-
71
from ariadne import gql, graphql_sync, ObjectType, QueryType, make_executable_schema
82
from ariadne.asgi import GraphQL
93
from fastapi import FastAPI

tests/integrations/asgi/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
22

3-
asyncio = pytest.importorskip("asyncio")
4-
pytest_asyncio = pytest.importorskip("pytest_asyncio")
3+
pytest.importorskip("asyncio")
4+
pytest.importorskip("pytest_asyncio")
5+
pytest.importorskip("async_asgi_testclient")

tests/integrations/asgi/test_asgi.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from sentry_sdk.integrations._asgi_common import _get_ip, _get_headers
99
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware, _looks_like_asgi3
1010

11-
async_asgi_testclient = pytest.importorskip("async_asgi_testclient")
1211
from async_asgi_testclient import TestClient
1312

1413

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import pytest
22

33
pytest.importorskip("asyncpg")
4+
pytest.importorskip("pytest_asyncio")

tests/integrations/asyncpg/test_asyncpg.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
import asyncpg
2424
import pytest
25+
26+
import pytest_asyncio
27+
2528
from asyncpg import connect, Connection
2629

2730
from sentry_sdk import capture_message
2831
from sentry_sdk.integrations.asyncpg import AsyncPGIntegration
29-
from tests.integrations.asgi import pytest_asyncio
3032

3133

3234
PG_CONNECTION_URI = f"postgresql://{PG_USER}:{PG_PASSWORD}@{PG_HOST}/{PG_NAME}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("boto3")

tests/integrations/aws_lambda/test_aws.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import pytest
2424

25-
boto3 = pytest.importorskip("boto3")
2625

2726
LAMBDA_PRELUDE = """
2827
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration, get_lambda_bootstrap

tests/integrations/beam/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("apache_beam")

tests/integrations/beam/test_beam.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import pytest
22
import inspect
33

4-
pytest.importorskip("apache_beam")
5-
64
import dill
75

86
from sentry_sdk.integrations.beam import (

tests/integrations/bottle/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("bottle")

tests/integrations/bottle/test_bottle.py

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
import pytest
33
import logging
44

5-
6-
pytest.importorskip("bottle")
7-
85
from io import BytesIO
96
from bottle import Bottle, debug as set_debug, abort, redirect
107
from sentry_sdk import capture_message

tests/integrations/celery/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("celery")

tests/integrations/celery/test_celery.py

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import pytest
44

5-
pytest.importorskip("celery")
6-
75
from sentry_sdk import Hub, configure_scope, start_transaction, get_current_span
86
from sentry_sdk.integrations.celery import CeleryIntegration, _get_headers
97

tests/integrations/celery/test_celery_beat_crons.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
22

3-
pytest.importorskip("celery")
4-
53
from sentry_sdk.integrations.celery import (
64
_get_headers,
75
_get_humanized_interval,

tests/integrations/django/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
django = pytest.importorskip("django")
3+
pytest.importorskip("django")

tests/integrations/falcon/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("falcon")

tests/integrations/falcon/test_falcon.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import pytest
66

7-
pytest.importorskip("falcon")
8-
97
import falcon
108
import falcon.testing
119
import sentry_sdk

tests/integrations/fastapi/test_fastapi.py

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import pytest
66
from sentry_sdk.integrations.fastapi import FastApiIntegration
77

8-
fastapi = pytest.importorskip("fastapi")
9-
108
from fastapi import FastAPI, Request
119
from fastapi.testclient import TestClient
1210
from fastapi.middleware.trustedhost import TrustedHostMiddleware

tests/integrations/flask/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("flask")

tests/integrations/flask/test_flask.py

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
from io import BytesIO
77

8-
flask = pytest.importorskip("flask")
9-
108
from flask import (
119
Flask,
1210
Response,

tests/integrations/gql/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("gql")

tests/integrations/gql/test_gql.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
22

3-
pytest.importorskip("gql")
4-
53
import responses
64
from gql import gql
75
from gql import Client
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pytest
2+
3+
pytest.importorskip("graphene")
4+
pytest.importorskip("fastapi")
5+
pytest.importorskip("flask")

tests/integrations/graphene/test_graphene_py3.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import pytest
2-
3-
pytest.importorskip("graphene")
4-
pytest.importorskip("fastapi")
5-
pytest.importorskip("flask")
6-
71
from fastapi import FastAPI, Request
82
from fastapi.testclient import TestClient
93
from flask import Flask, request, jsonify
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
django = pytest.importorskip("opentelemetry")
3+
pytest.importorskip("opentelemetry")
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
pure_eval = pytest.importorskip("pure_eval")
3+
pytest.importorskip("pure_eval")
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
pyramid = pytest.importorskip("pyramid")
3+
pytest.importorskip("pyramid")

tests/integrations/quart/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
quart = pytest.importorskip("quart")
3+
pytest.importorskip("quart")

tests/integrations/quart/test_quart.py

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from sentry_sdk.integrations.logging import LoggingIntegration
1515
import sentry_sdk.integrations.quart as quart_sentry
1616

17-
quart = pytest.importorskip("quart")
18-
1917
from quart import Quart, Response, abort, stream_with_context
2018
from quart.views import View
2119

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("requests")

tests/integrations/requests/test_requests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import pytest
1+
import requests
22
import responses
33

4-
requests = pytest.importorskip("requests")
4+
import pytest
55

66
from sentry_sdk import capture_message
77
from sentry_sdk.consts import SPANDATA

tests/integrations/rq/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
rq = pytest.importorskip("rq")
3+
pytest.importorskip("rq")

tests/integrations/sanic/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
sanic = pytest.importorskip("sanic")
3+
pytest.importorskip("sanic")

tests/integrations/spark/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pytest
2+
3+
pytest.importorskip("pyspark")
4+
pytest.importorskip("py4j")

tests/integrations/spark/test_spark.py

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
from sentry_sdk.integrations.spark.spark_worker import SparkWorkerIntegration
1010

11-
12-
pytest.importorskip("pyspark")
13-
pytest.importorskip("py4j")
14-
1511
from pyspark import SparkContext
1612

1713
from py4j.protocol import Py4JJavaError

tests/integrations/starlette/test_starlette.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
StarletteRequestExtractor,
2525
)
2626

27-
starlette = pytest.importorskip("starlette")
27+
import starlette
2828
from starlette.authentication import (
2929
AuthCredentials,
3030
AuthenticationBackend,

tests/integrations/starlite/test_starlite.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
from sentry_sdk import capture_exception, capture_message, last_event_id
66
from sentry_sdk.integrations.starlite import StarliteIntegration
77

8-
starlite = pytest.importorskip("starlite")
9-
108
from typing import Any, Dict
119

10+
import starlite
1211
from starlite import AbstractMiddleware, LoggingConfig, Starlite, get, Controller
1312
from starlite.middleware import LoggingMiddlewareConfig, RateLimitConfig
1413
from starlite.middleware.session.memory_backend import MemoryBackendConfig
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
tornado = pytest.importorskip("tornado")
3+
pytest.importorskip("tornado")
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("trytond")

tests/integrations/trytond/test_trytond.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import pytest
2-
3-
pytest.importorskip("trytond")
4-
51
import json
62
import unittest.mock
73

4+
import pytest
5+
86
import trytond
97
from trytond.exceptions import TrytonException as TrytondBaseException
108
from trytond.exceptions import UserError as TrytondUserError

0 commit comments

Comments
 (0)