Skip to content

Commit e6c8798

Browse files
authored
toxgen: Migrate fastapi (#4302)
With this we've migrated the whole Web 1 group, yay! So the whole `-latest` category is gone for Web 1, too. Also removed some `pytest.mark.asyncio`s on sync tests.
1 parent 0851458 commit e6c8798

File tree

6 files changed

+43
-123
lines changed

6 files changed

+43
-123
lines changed

.github/workflows/test-integrations-web-1.yml

-89
Original file line numberDiff line numberDiff line change
@@ -22,95 +22,6 @@ env:
2222
CACHED_BUILD_PATHS: |
2323
${{ github.workspace }}/dist-serverless
2424
jobs:
25-
test-web_1-latest:
26-
name: Web 1 (latest)
27-
timeout-minutes: 30
28-
runs-on: ${{ matrix.os }}
29-
strategy:
30-
fail-fast: false
31-
matrix:
32-
python-version: ["3.8","3.12","3.13"]
33-
# python3.6 reached EOL and is no longer being supported on
34-
# new versions of hosted runners on Github Actions
35-
# ubuntu-20.04 is the last version that supported python3.6
36-
# see https://github.com/actions/setup-python/issues/544#issuecomment-1332535877
37-
os: [ubuntu-22.04]
38-
services:
39-
postgres:
40-
image: postgres
41-
env:
42-
POSTGRES_PASSWORD: sentry
43-
# Set health checks to wait until postgres has started
44-
options: >-
45-
--health-cmd pg_isready
46-
--health-interval 10s
47-
--health-timeout 5s
48-
--health-retries 5
49-
# Maps tcp port 5432 on service container to the host
50-
ports:
51-
- 5432:5432
52-
env:
53-
SENTRY_PYTHON_TEST_POSTGRES_HOST: ${{ matrix.python-version == '3.6' && 'postgres' || 'localhost' }}
54-
SENTRY_PYTHON_TEST_POSTGRES_USER: postgres
55-
SENTRY_PYTHON_TEST_POSTGRES_PASSWORD: sentry
56-
# Use Docker container only for Python 3.6
57-
container: ${{ matrix.python-version == '3.6' && 'python:3.6' || null }}
58-
steps:
59-
- uses: actions/[email protected]
60-
- uses: actions/setup-python@v5
61-
if: ${{ matrix.python-version != '3.6' }}
62-
with:
63-
python-version: ${{ matrix.python-version }}
64-
allow-prereleases: true
65-
- name: Setup Test Env
66-
run: |
67-
pip install "coverage[toml]" tox
68-
- name: Erase coverage
69-
run: |
70-
coverage erase
71-
- name: Test django latest
72-
run: |
73-
set -x # print commands that are executed
74-
./scripts/runtox.sh "py${{ matrix.python-version }}-django-latest"
75-
- name: Test flask latest
76-
run: |
77-
set -x # print commands that are executed
78-
./scripts/runtox.sh "py${{ matrix.python-version }}-flask-latest"
79-
- name: Test starlette latest
80-
run: |
81-
set -x # print commands that are executed
82-
./scripts/runtox.sh "py${{ matrix.python-version }}-starlette-latest"
83-
- name: Test fastapi latest
84-
run: |
85-
set -x # print commands that are executed
86-
./scripts/runtox.sh "py${{ matrix.python-version }}-fastapi-latest"
87-
- name: Generate coverage XML (Python 3.6)
88-
if: ${{ !cancelled() && matrix.python-version == '3.6' }}
89-
run: |
90-
export COVERAGE_RCFILE=.coveragerc36
91-
coverage combine .coverage-sentry-*
92-
coverage xml --ignore-errors
93-
- name: Generate coverage XML
94-
if: ${{ !cancelled() && matrix.python-version != '3.6' }}
95-
run: |
96-
coverage combine .coverage-sentry-*
97-
coverage xml
98-
- name: Upload coverage to Codecov
99-
if: ${{ !cancelled() }}
100-
uses: codecov/[email protected]
101-
with:
102-
token: ${{ secrets.CODECOV_TOKEN }}
103-
files: coverage.xml
104-
# make sure no plugins alter our coverage reports
105-
plugin: noop
106-
verbose: true
107-
- name: Upload test results to Codecov
108-
if: ${{ !cancelled() }}
109-
uses: codecov/test-results-action@v1
110-
with:
111-
token: ${{ secrets.CODECOV_TOKEN }}
112-
files: .junitxml
113-
verbose: true
11425
test-web_1-pinned:
11526
name: Web 1 (pinned)
11627
timeout-minutes: 30

scripts/populate_tox/config.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@
5555
"package": "falcon",
5656
"python": "<3.13",
5757
},
58+
"fastapi": {
59+
"package": "fastapi",
60+
"deps": {
61+
"*": [
62+
"httpx",
63+
"pytest-asyncio",
64+
"python-multipart",
65+
"requests",
66+
"anyio<4",
67+
],
68+
# There's an incompatibility between FastAPI's TestClient, which is
69+
# actually Starlette's TestClient, which is actually httpx's Client.
70+
# httpx dropped a deprecated Client argument in 0.28.0, Starlette
71+
# dropped it from its TestClient in 0.37.2, and FastAPI only pinned
72+
# Starlette>=0.37.2 from version 0.110.1 onwards -- so for older
73+
# FastAPI versions we use older httpx which still supports the
74+
# deprecated argument.
75+
"<0.110.1": ["httpx<0.28.0"],
76+
"py3.6": ["aiocontextvars"],
77+
},
78+
},
5879
"flask": {
5980
"package": "flask",
6081
"deps": {
@@ -137,7 +158,8 @@
137158
"jinja2",
138159
"httpx",
139160
],
140-
"<0.37": ["httpx<0.28.0"],
161+
# See the comment on FastAPI's httpx bound for more info
162+
"<0.37.2": ["httpx<0.28.0"],
141163
"<0.15": ["jinja2<3.1"],
142164
"py3.6": ["aiocontextvars"],
143165
},

scripts/populate_tox/populate_tox.py

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
"boto3",
7676
"chalice",
7777
"cohere",
78-
"fastapi",
7978
"gcp",
8079
"httpx",
8180
"langchain",

scripts/populate_tox/tox.jinja

-14
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ envlist =
8080
{py3.9,py3.11,py3.12}-cohere-v5
8181
{py3.9,py3.11,py3.12}-cohere-latest
8282

83-
# FastAPI
84-
{py3.7,py3.10}-fastapi-v{0.79}
85-
{py3.8,py3.12,py3.13}-fastapi-latest
86-
8783
# GCP
8884
{py3.7}-gcp
8985

@@ -252,16 +248,6 @@ deps =
252248
cohere-v5: cohere~=5.3.3
253249
cohere-latest: cohere
254250
255-
# FastAPI
256-
fastapi: httpx
257-
# (this is a dependency of httpx)
258-
fastapi: anyio<4.0.0
259-
fastapi: pytest-asyncio
260-
fastapi: python-multipart
261-
fastapi: requests
262-
fastapi-v{0.79}: fastapi~=0.79.0
263-
fastapi-latest: fastapi
264-
265251
# HTTPX
266252
httpx-v0.16: pytest-httpx==0.10.0
267253
httpx-v0.18: pytest-httpx==0.12.0

tests/integrations/fastapi/test_fastapi.py

-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ async def _error(request: Request):
247247
assert event["request"]["headers"]["authorization"] == "[Filtered]"
248248

249249

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

278277

279-
@pytest.mark.asyncio
280278
def test_response_status_code_error_in_transaction_context(
281279
sentry_init,
282280
capture_envelopes,
@@ -313,7 +311,6 @@ def test_response_status_code_error_in_transaction_context(
313311
assert transaction["contexts"]["response"]["status_code"] == 500
314312

315313

316-
@pytest.mark.asyncio
317314
def test_response_status_code_not_found_in_transaction_context(
318315
sentry_init,
319316
capture_envelopes,

tox.ini

+20-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# The file (and all resulting CI YAMLs) then need to be regenerated via
1111
# "scripts/generate-test-files.sh".
1212
#
13-
# Last generated: 2025-04-15T11:48:52.985806+00:00
13+
# Last generated: 2025-04-15T14:38:12.763407+00:00
1414

1515
[tox]
1616
requires =
@@ -80,10 +80,6 @@ envlist =
8080
{py3.9,py3.11,py3.12}-cohere-v5
8181
{py3.9,py3.11,py3.12}-cohere-latest
8282

83-
# FastAPI
84-
{py3.7,py3.10}-fastapi-v{0.79}
85-
{py3.8,py3.12,py3.13}-fastapi-latest
86-
8783
# GCP
8884
{py3.7}-gcp
8985

@@ -260,6 +256,11 @@ envlist =
260256
{py3.8,py3.11,py3.12}-starlette-v0.36.3
261257
{py3.9,py3.12,py3.13}-starlette-v0.46.2
262258

259+
{py3.6,py3.9,py3.10}-fastapi-v0.79.1
260+
{py3.7,py3.10,py3.11}-fastapi-v0.91.0
261+
{py3.7,py3.10,py3.11}-fastapi-v0.103.2
262+
{py3.8,py3.12,py3.13}-fastapi-v0.115.12
263+
263264

264265
# ~~~ Web 2 ~~~
265266
{py3.6,py3.7}-bottle-v0.12.25
@@ -394,16 +395,6 @@ deps =
394395
cohere-v5: cohere~=5.3.3
395396
cohere-latest: cohere
396397

397-
# FastAPI
398-
fastapi: httpx
399-
# (this is a dependency of httpx)
400-
fastapi: anyio<4.0.0
401-
fastapi: pytest-asyncio
402-
fastapi: python-multipart
403-
fastapi: requests
404-
fastapi-v{0.79}: fastapi~=0.79.0
405-
fastapi-latest: fastapi
406-
407398
# HTTPX
408399
httpx-v0.16: pytest-httpx==0.10.0
409400
httpx-v0.18: pytest-httpx==0.12.0
@@ -695,6 +686,20 @@ deps =
695686
starlette-v0.36.3: httpx<0.28.0
696687
py3.6-starlette: aiocontextvars
697688

689+
fastapi-v0.79.1: fastapi==0.79.1
690+
fastapi-v0.91.0: fastapi==0.91.0
691+
fastapi-v0.103.2: fastapi==0.103.2
692+
fastapi-v0.115.12: fastapi==0.115.12
693+
fastapi: httpx
694+
fastapi: pytest-asyncio
695+
fastapi: python-multipart
696+
fastapi: requests
697+
fastapi: anyio<4
698+
fastapi-v0.79.1: httpx<0.28.0
699+
fastapi-v0.91.0: httpx<0.28.0
700+
fastapi-v0.103.2: httpx<0.28.0
701+
py3.6-fastapi: aiocontextvars
702+
698703

699704
# ~~~ Web 2 ~~~
700705
bottle-v0.12.25: bottle==0.12.25

0 commit comments

Comments
 (0)