Skip to content

Commit 297c09e

Browse files
committed
Fix test mypy issues
Signed-off-by: Michael Honaker <mchonaker@gmail.com>
1 parent 753e790 commit 297c09e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/test_formparsers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

33
import os
4+
import threading
45
from contextlib import AbstractContextManager, nullcontext as does_not_raise
56
from io import BytesIO
67
from pathlib import Path
78
from tempfile import SpooledTemporaryFile
8-
import threading
99
from typing import Any
1010
from unittest import mock
1111

@@ -321,21 +321,23 @@ def test_multipart_request_mixed_files_and_data(tmpdir: Path, test_client_factor
321321
}
322322

323323

324-
class ThreadTrackingSpooledTemporaryFile(SpooledTemporaryFile):
324+
class ThreadTrackingSpooledTemporaryFile(SpooledTemporaryFile[bytes]):
325325
"""Helper class to track which threads performed the rollover operation. This is
326326
not threadsafe/multi-test safe"""
327327

328-
rollover_threads: set[int] = set()
328+
rollover_threads: set[int | None] = set()
329329

330-
def rollover(self):
330+
def rollover(self) -> None:
331331
ThreadTrackingSpooledTemporaryFile.rollover_threads.add(threading.current_thread().ident)
332-
return super().rollover()
332+
super().rollover()
333333

334334

335335
def test_multipart_request_large_file(tmpdir: Path, test_client_factory: TestClientFactory) -> None:
336+
"""Test that Spooled file rollovers happen in background threads"""
336337
data = BytesIO(b" " * MultiPartParser.spool_max_size * 2)
337338

338339
# Mock the formparser to use our monitoring class
340+
ThreadTrackingSpooledTemporaryFile.rollover_threads.clear()
339341
with mock.patch("starlette.formparsers.SpooledTemporaryFile", ThreadTrackingSpooledTemporaryFile):
340342
client = test_client_factory(app_monitor_thread)
341343
response = client.post(

0 commit comments

Comments
 (0)