Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(starlette): Refactor shared test parametrization #3562

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions tests/integrations/fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from sentry_sdk.integrations.fastapi import FastApiIntegration
from sentry_sdk.integrations.starlette import StarletteIntegration

from tests.integrations.starlette import test_starlette


def fastapi_app_factory():
app = FastAPI()
Expand Down Expand Up @@ -503,25 +505,7 @@ def test_transaction_name_in_middleware(
)


@pytest.mark.parametrize(
"failed_request_status_codes,status_code,expected_error",
[
(None, 500, True),
(None, 400, False),
([500, 501], 500, True),
([500, 501], 401, False),
([range(400, 499)], 401, True),
([range(400, 499)], 500, False),
([range(400, 499), range(500, 599)], 300, False),
([range(400, 499), range(500, 599)], 403, True),
([range(400, 499), range(500, 599)], 503, True),
([range(400, 403), 500, 501], 401, True),
([range(400, 403), 500, 501], 405, False),
([range(400, 403), 500, 501], 501, True),
([range(400, 403), 500, 501], 503, False),
([None], 500, False),
],
)
@test_starlette.parametrize_test_configurable_status_codes
def test_configurable_status_codes(
sentry_init,
capture_events,
Expand Down
8 changes: 7 additions & 1 deletion tests/integrations/starlette/test_starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ def test_span_origin(sentry_init, capture_events):
assert span["origin"] == "auto.http.starlette"


@pytest.mark.parametrize(
parametrize_test_configurable_status_codes = pytest.mark.parametrize(
"failed_request_status_codes,status_code,expected_error",
[
(None, 500, True),
Expand All @@ -1152,6 +1152,12 @@ def test_span_origin(sentry_init, capture_events):
([None], 500, False),
],
)
"""Test cases for configurable status codes.
Also used by the FastAPI tests.
"""


@parametrize_test_configurable_status_codes
def test_configurable_status_codes(
sentry_init,
capture_events,
Expand Down
Loading