Skip to content

toxgen: Migrate fastapi #4302

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

Merged
merged 6 commits into from
Apr 15, 2025
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
89 changes: 0 additions & 89 deletions .github/workflows/test-integrations-web-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,95 +22,6 @@ env:
CACHED_BUILD_PATHS: |
${{ github.workspace }}/dist-serverless
jobs:
test-web_1-latest:
name: Web 1 (latest)
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8","3.12","3.13"]
# python3.6 reached EOL and is no longer being supported on
# new versions of hosted runners on Github Actions
# ubuntu-20.04 is the last version that supported python3.6
# see https://github.com/actions/setup-python/issues/544#issuecomment-1332535877
os: [ubuntu-22.04]
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: sentry
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
# Maps tcp port 5432 on service container to the host
ports:
- 5432:5432
env:
SENTRY_PYTHON_TEST_POSTGRES_HOST: ${{ matrix.python-version == '3.6' && 'postgres' || 'localhost' }}
SENTRY_PYTHON_TEST_POSTGRES_USER: postgres
SENTRY_PYTHON_TEST_POSTGRES_PASSWORD: sentry
# Use Docker container only for Python 3.6
container: ${{ matrix.python-version == '3.6' && 'python:3.6' || null }}
steps:
- uses: actions/[email protected]
- uses: actions/setup-python@v5
if: ${{ matrix.python-version != '3.6' }}
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Setup Test Env
run: |
pip install "coverage[toml]" tox
- name: Erase coverage
run: |
coverage erase
- name: Test django latest
run: |
set -x # print commands that are executed
./scripts/runtox.sh "py${{ matrix.python-version }}-django-latest"
- name: Test flask latest
run: |
set -x # print commands that are executed
./scripts/runtox.sh "py${{ matrix.python-version }}-flask-latest"
- name: Test starlette latest
run: |
set -x # print commands that are executed
./scripts/runtox.sh "py${{ matrix.python-version }}-starlette-latest"
- name: Test fastapi latest
run: |
set -x # print commands that are executed
./scripts/runtox.sh "py${{ matrix.python-version }}-fastapi-latest"
- name: Generate coverage XML (Python 3.6)
if: ${{ !cancelled() && matrix.python-version == '3.6' }}
run: |
export COVERAGE_RCFILE=.coveragerc36
coverage combine .coverage-sentry-*
coverage xml --ignore-errors
- name: Generate coverage XML
if: ${{ !cancelled() && matrix.python-version != '3.6' }}
run: |
coverage combine .coverage-sentry-*
coverage xml
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
# make sure no plugins alter our coverage reports
plugin: noop
verbose: true
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: .junitxml
verbose: true
test-web_1-pinned:
name: Web 1 (pinned)
timeout-minutes: 30
Expand Down
24 changes: 23 additions & 1 deletion scripts/populate_tox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@
"package": "falcon",
"python": "<3.13",
},
"fastapi": {
"package": "fastapi",
"deps": {
"*": [
"httpx",
"pytest-asyncio",
"python-multipart",
"requests",
"anyio<4",
],
# There's an incompatibility between FastAPI's TestClient, which is
# actually Starlette's TestClient, which is actually httpx's Client.
# httpx dropped a deprecated Client argument in 0.28.0, Starlette
# dropped it from its TestClient in 0.37.2, and FastAPI only pinned
# Starlette>=0.37.2 from version 0.110.1 onwards -- so for older
# FastAPI versions we use older httpx which still supports the
# deprecated argument.
"<0.110.1": ["httpx<0.28.0"],
"py3.6": ["aiocontextvars"],
},
},
"flask": {
"package": "flask",
"deps": {
Expand Down Expand Up @@ -137,7 +158,8 @@
"jinja2",
"httpx",
],
"<0.37": ["httpx<0.28.0"],
# See the comment on FastAPI's httpx bound for more info
"<0.37.2": ["httpx<0.28.0"],
"<0.15": ["jinja2<3.1"],
"py3.6": ["aiocontextvars"],
},
Expand Down
1 change: 0 additions & 1 deletion scripts/populate_tox/populate_tox.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"boto3",
"chalice",
"cohere",
"fastapi",
"gcp",
"httpx",
"langchain",
Expand Down
14 changes: 0 additions & 14 deletions scripts/populate_tox/tox.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ envlist =
{py3.9,py3.11,py3.12}-cohere-v5
{py3.9,py3.11,py3.12}-cohere-latest

# FastAPI
{py3.7,py3.10}-fastapi-v{0.79}
{py3.8,py3.12,py3.13}-fastapi-latest

# GCP
{py3.7}-gcp

Expand Down Expand Up @@ -252,16 +248,6 @@ deps =
cohere-v5: cohere~=5.3.3
cohere-latest: cohere

# FastAPI
fastapi: httpx
# (this is a dependency of httpx)
fastapi: anyio<4.0.0
fastapi: pytest-asyncio
fastapi: python-multipart
fastapi: requests
fastapi-v{0.79}: fastapi~=0.79.0
fastapi-latest: fastapi

# HTTPX
httpx-v0.16: pytest-httpx==0.10.0
httpx-v0.18: pytest-httpx==0.12.0
Expand Down
3 changes: 0 additions & 3 deletions tests/integrations/fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ async def _error(request: Request):
assert event["request"]["headers"]["authorization"] == "[Filtered]"


@pytest.mark.asyncio
def test_response_status_code_ok_in_transaction_context(sentry_init, capture_envelopes):
"""
Tests that the response status code is added to the transaction "response" context.
Expand Down Expand Up @@ -276,7 +275,6 @@ def test_response_status_code_ok_in_transaction_context(sentry_init, capture_env
assert transaction["contexts"]["response"]["status_code"] == 200


@pytest.mark.asyncio
def test_response_status_code_error_in_transaction_context(
sentry_init,
capture_envelopes,
Expand Down Expand Up @@ -313,7 +311,6 @@ def test_response_status_code_error_in_transaction_context(
assert transaction["contexts"]["response"]["status_code"] == 500


@pytest.mark.asyncio
def test_response_status_code_not_found_in_transaction_context(
sentry_init,
capture_envelopes,
Expand Down
35 changes: 20 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# The file (and all resulting CI YAMLs) then need to be regenerated via
# "scripts/generate-test-files.sh".
#
# Last generated: 2025-04-15T11:48:52.985806+00:00
# Last generated: 2025-04-15T14:38:12.763407+00:00

[tox]
requires =
Expand Down Expand Up @@ -80,10 +80,6 @@ envlist =
{py3.9,py3.11,py3.12}-cohere-v5
{py3.9,py3.11,py3.12}-cohere-latest

# FastAPI
{py3.7,py3.10}-fastapi-v{0.79}
{py3.8,py3.12,py3.13}-fastapi-latest

# GCP
{py3.7}-gcp

Expand Down Expand Up @@ -260,6 +256,11 @@ envlist =
{py3.8,py3.11,py3.12}-starlette-v0.36.3
{py3.9,py3.12,py3.13}-starlette-v0.46.2

{py3.6,py3.9,py3.10}-fastapi-v0.79.1
{py3.7,py3.10,py3.11}-fastapi-v0.91.0
{py3.7,py3.10,py3.11}-fastapi-v0.103.2
{py3.8,py3.12,py3.13}-fastapi-v0.115.12


# ~~~ Web 2 ~~~
{py3.6,py3.7}-bottle-v0.12.25
Expand Down Expand Up @@ -394,16 +395,6 @@ deps =
cohere-v5: cohere~=5.3.3
cohere-latest: cohere

# FastAPI
fastapi: httpx
# (this is a dependency of httpx)
fastapi: anyio<4.0.0
fastapi: pytest-asyncio
fastapi: python-multipart
fastapi: requests
fastapi-v{0.79}: fastapi~=0.79.0
fastapi-latest: fastapi

# HTTPX
httpx-v0.16: pytest-httpx==0.10.0
httpx-v0.18: pytest-httpx==0.12.0
Expand Down Expand Up @@ -695,6 +686,20 @@ deps =
starlette-v0.36.3: httpx<0.28.0
py3.6-starlette: aiocontextvars

fastapi-v0.79.1: fastapi==0.79.1
fastapi-v0.91.0: fastapi==0.91.0
fastapi-v0.103.2: fastapi==0.103.2
fastapi-v0.115.12: fastapi==0.115.12
fastapi: httpx
fastapi: pytest-asyncio
fastapi: python-multipart
fastapi: requests
fastapi: anyio<4
fastapi-v0.79.1: httpx<0.28.0
fastapi-v0.91.0: httpx<0.28.0
fastapi-v0.103.2: httpx<0.28.0
py3.6-fastapi: aiocontextvars


# ~~~ Web 2 ~~~
bottle-v0.12.25: bottle==0.12.25
Expand Down
Loading