Skip to content

Commit

Permalink
Move importorskips in tests to __init__.py files (#2412)
Browse files Browse the repository at this point in the history
Let's make the placement of the `importorskip`s consistent.
  • Loading branch information
sentrivana committed Oct 4, 2023
1 parent fb39f22 commit 963e0d5
Show file tree
Hide file tree
Showing 42 changed files with 63 additions and 58 deletions.
2 changes: 1 addition & 1 deletion tests/integrations/aiohttp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

aiohttp = pytest.importorskip("aiohttp")
pytest.importorskip("aiohttp")
5 changes: 5 additions & 0 deletions tests/integrations/ariadne/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pytest

pytest.importorskip("ariadne")
pytest.importorskip("fastapi")
pytest.importorskip("flask")
6 changes: 0 additions & 6 deletions tests/integrations/ariadne/test_ariadne.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import pytest

pytest.importorskip("ariadne")
pytest.importorskip("fastapi")
pytest.importorskip("flask")

from ariadne import gql, graphql_sync, ObjectType, QueryType, make_executable_schema
from ariadne.asgi import GraphQL
from fastapi import FastAPI
Expand Down
5 changes: 3 additions & 2 deletions tests/integrations/asgi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

asyncio = pytest.importorskip("asyncio")
pytest_asyncio = pytest.importorskip("pytest_asyncio")
pytest.importorskip("asyncio")
pytest.importorskip("pytest_asyncio")
pytest.importorskip("async_asgi_testclient")
1 change: 0 additions & 1 deletion tests/integrations/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from sentry_sdk.integrations._asgi_common import _get_ip, _get_headers
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware, _looks_like_asgi3

async_asgi_testclient = pytest.importorskip("async_asgi_testclient")
from async_asgi_testclient import TestClient


Expand Down
1 change: 1 addition & 0 deletions tests/integrations/asyncpg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest

pytest.importorskip("asyncpg")
pytest.importorskip("pytest_asyncio")
4 changes: 3 additions & 1 deletion tests/integrations/asyncpg/test_asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@

import asyncpg
import pytest

import pytest_asyncio

from asyncpg import connect, Connection

from sentry_sdk import capture_message
from sentry_sdk.integrations.asyncpg import AsyncPGIntegration
from tests.integrations.asgi import pytest_asyncio


PG_CONNECTION_URI = f"postgresql://{PG_USER}:{PG_PASSWORD}@{PG_HOST}/{PG_NAME}"
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/aws_lambda/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("boto3")
1 change: 0 additions & 1 deletion tests/integrations/aws_lambda/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import pytest

boto3 = pytest.importorskip("boto3")

LAMBDA_PRELUDE = """
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration, get_lambda_bootstrap
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/beam/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("apache_beam")
2 changes: 0 additions & 2 deletions tests/integrations/beam/test_beam.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
import inspect

pytest.importorskip("apache_beam")

import dill

from sentry_sdk.integrations.beam import (
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/bottle/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("bottle")
3 changes: 0 additions & 3 deletions tests/integrations/bottle/test_bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import pytest
import logging


pytest.importorskip("bottle")

from io import BytesIO
from bottle import Bottle, debug as set_debug, abort, redirect
from sentry_sdk import capture_message
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("celery")
2 changes: 0 additions & 2 deletions tests/integrations/celery/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import pytest

pytest.importorskip("celery")

from sentry_sdk import Hub, configure_scope, start_transaction, get_current_span
from sentry_sdk.integrations.celery import CeleryIntegration, _get_headers

Expand Down
2 changes: 0 additions & 2 deletions tests/integrations/celery/test_celery_beat_crons.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

pytest.importorskip("celery")

from sentry_sdk.integrations.celery import (
_get_headers,
_get_humanized_interval,
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/django/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

django = pytest.importorskip("django")
pytest.importorskip("django")
3 changes: 3 additions & 0 deletions tests/integrations/falcon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("falcon")
2 changes: 0 additions & 2 deletions tests/integrations/falcon/test_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import pytest

pytest.importorskip("falcon")

import falcon
import falcon.testing
import sentry_sdk
Expand Down
2 changes: 0 additions & 2 deletions tests/integrations/fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import pytest
from sentry_sdk.integrations.fastapi import FastApiIntegration

fastapi = pytest.importorskip("fastapi")

from fastapi import FastAPI, Request
from fastapi.testclient import TestClient
from fastapi.middleware.trustedhost import TrustedHostMiddleware
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/flask/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("flask")
2 changes: 0 additions & 2 deletions tests/integrations/flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from io import BytesIO

flask = pytest.importorskip("flask")

from flask import (
Flask,
Response,
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/gql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("gql")
2 changes: 0 additions & 2 deletions tests/integrations/gql/test_gql.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

pytest.importorskip("gql")

import responses
from gql import gql
from gql import Client
Expand Down
5 changes: 5 additions & 0 deletions tests/integrations/graphene/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pytest

pytest.importorskip("graphene")
pytest.importorskip("fastapi")
pytest.importorskip("flask")
6 changes: 0 additions & 6 deletions tests/integrations/graphene/test_graphene_py3.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import pytest

pytest.importorskip("graphene")
pytest.importorskip("fastapi")
pytest.importorskip("flask")

from fastapi import FastAPI, Request
from fastapi.testclient import TestClient
from flask import Flask, request, jsonify
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/opentelemetry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

django = pytest.importorskip("opentelemetry")
pytest.importorskip("opentelemetry")
2 changes: 1 addition & 1 deletion tests/integrations/pure_eval/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

pure_eval = pytest.importorskip("pure_eval")
pytest.importorskip("pure_eval")
2 changes: 1 addition & 1 deletion tests/integrations/pyramid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

pyramid = pytest.importorskip("pyramid")
pytest.importorskip("pyramid")
2 changes: 1 addition & 1 deletion tests/integrations/quart/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

quart = pytest.importorskip("quart")
pytest.importorskip("quart")
2 changes: 0 additions & 2 deletions tests/integrations/quart/test_quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from sentry_sdk.integrations.logging import LoggingIntegration
import sentry_sdk.integrations.quart as quart_sentry

quart = pytest.importorskip("quart")

from quart import Quart, Response, abort, stream_with_context
from quart.views import View

Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/requests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("requests")
4 changes: 2 additions & 2 deletions tests/integrations/requests/test_requests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import requests
import responses

requests = pytest.importorskip("requests")
import pytest

from sentry_sdk import capture_message
from sentry_sdk.consts import SPANDATA
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/rq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

rq = pytest.importorskip("rq")
pytest.importorskip("rq")
2 changes: 1 addition & 1 deletion tests/integrations/sanic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

sanic = pytest.importorskip("sanic")
pytest.importorskip("sanic")
4 changes: 4 additions & 0 deletions tests/integrations/spark/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pytest

pytest.importorskip("pyspark")
pytest.importorskip("py4j")
4 changes: 0 additions & 4 deletions tests/integrations/spark/test_spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

from sentry_sdk.integrations.spark.spark_worker import SparkWorkerIntegration


pytest.importorskip("pyspark")
pytest.importorskip("py4j")

from pyspark import SparkContext

from py4j.protocol import Py4JJavaError
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/starlette/test_starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
StarletteRequestExtractor,
)

starlette = pytest.importorskip("starlette")
import starlette
from starlette.authentication import (
AuthCredentials,
AuthenticationBackend,
Expand Down
3 changes: 1 addition & 2 deletions tests/integrations/starlite/test_starlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from sentry_sdk import capture_exception, capture_message, last_event_id
from sentry_sdk.integrations.starlite import StarliteIntegration

starlite = pytest.importorskip("starlite")

from typing import Any, Dict

import starlite
from starlite import AbstractMiddleware, LoggingConfig, Starlite, get, Controller
from starlite.middleware import LoggingMiddlewareConfig, RateLimitConfig
from starlite.middleware.session.memory_backend import MemoryBackendConfig
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/tornado/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

tornado = pytest.importorskip("tornado")
pytest.importorskip("tornado")
3 changes: 3 additions & 0 deletions tests/integrations/trytond/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("trytond")
6 changes: 2 additions & 4 deletions tests/integrations/trytond/test_trytond.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pytest

pytest.importorskip("trytond")

import json
import unittest.mock

import pytest

import trytond
from trytond.exceptions import TrytonException as TrytondBaseException
from trytond.exceptions import UserError as TrytondUserError
Expand Down

0 comments on commit 963e0d5

Please sign in to comment.