Reenable pylint broad exception (#2536)

This commit is contained in:
Riccardo Magliocchetti
2024-05-24 20:12:53 +02:00
committed by GitHub
parent c1a51fde96
commit e6409568c1
8 changed files with 20 additions and 13 deletions

View File

@ -492,4 +492,4 @@ min-public-methods=2
# Exceptions that will emit a warning when being caught. Defaults to
# "Exception".
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception

View File

@ -17,6 +17,7 @@ from unittest import mock
from unittest.mock import MagicMock
import aiopg
import psycopg2
import opentelemetry.instrumentation.aiopg
from opentelemetry import trace as trace_api
@ -384,7 +385,9 @@ class TestAiopgIntegration(TestBase):
span.attributes[SpanAttributes.DB_STATEMENT], "Test query"
)
self.assertIs(span.status.status_code, trace_api.StatusCode.ERROR)
self.assertEqual(span.status.description, "Exception: Test Exception")
self.assertEqual(
span.status.description, "ProgrammingError: Test Exception"
)
def test_executemany(self):
db_integration = AiopgIntegration(self.tracer, "testcomponent")
@ -570,17 +573,17 @@ class MockCursor:
# pylint: disable=unused-argument, no-self-use
async def execute(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")
# pylint: disable=unused-argument, no-self-use
async def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")
# pylint: disable=unused-argument, no-self-use
async def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")
def close(self):
pass

View File

@ -22,4 +22,5 @@ def rest_api_handler(event, context):
def handler_exc(event, context):
# pylint: disable=broad-exception-raised
raise Exception("500 internal server error")

View File

@ -419,11 +419,13 @@ class MockCursor:
# pylint: disable=unused-argument, no-self-use
def execute(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")
# pylint: disable=unused-argument, no-self-use
def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")
self.query = query
self.params = params
@ -431,4 +433,5 @@ class MockCursor:
# pylint: disable=unused-argument, no-self-use
def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")

View File

@ -47,11 +47,11 @@ def response_hook(span, response):
def request_hook_with_exception(_span, _request):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised
def response_hook_with_exception(_span, _response):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised
@pytest.mark.asyncio

View File

@ -73,11 +73,11 @@ def response_hook(span, response):
def request_hook_with_exception(_span, _request):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised
def response_hook_with_exception(_span, _response):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised
class TestHooks(TestBase):

View File

@ -53,17 +53,17 @@ class MockAsyncCursor:
# pylint: disable=unused-argument, no-self-use
async def execute(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")
# pylint: disable=unused-argument, no-self-use
async def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")
# pylint: disable=unused-argument, no-self-use
async def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")
async def __aenter__(self, *args, **kwargs):
return self

View File

@ -99,7 +99,7 @@ class RequestsIntegrationTestBase(abc.ABC):
@staticmethod
def base_exception_callback(*_, **__):
raise Exception("test")
raise Exception("test") # pylint: disable=broad-exception-raised
def assert_span(self, exporter=None, num_spans=1):
if exporter is None: