66
77
88import pytest
9- import pytest_asyncio
109
1110from llama_stack .apis .common .responses import Order
1211from llama_stack .apis .files import OpenAIFilePurpose
@@ -29,7 +28,7 @@ async def read(self):
2928 return self .content
3029
3130
32- @pytest_asyncio .fixture
31+ @pytest .fixture
3332async def files_provider (tmp_path ):
3433 """Create a files provider with temporary storage for testing."""
3534 storage_dir = tmp_path / "files"
@@ -68,7 +67,6 @@ def large_file():
6867class TestOpenAIFilesAPI :
6968 """Test suite for OpenAI Files API endpoints."""
7069
71- @pytest .mark .asyncio
7270 async def test_upload_file_success (self , files_provider , sample_text_file ):
7371 """Test successful file upload."""
7472 # Upload file
@@ -82,7 +80,6 @@ async def test_upload_file_success(self, files_provider, sample_text_file):
8280 assert result .created_at > 0
8381 assert result .expires_at > result .created_at
8482
85- @pytest .mark .asyncio
8683 async def test_upload_different_purposes (self , files_provider , sample_text_file ):
8784 """Test uploading files with different purposes."""
8885 purposes = list (OpenAIFilePurpose )
@@ -93,7 +90,6 @@ async def test_upload_different_purposes(self, files_provider, sample_text_file)
9390 uploaded_files .append (result )
9491 assert result .purpose == purpose
9592
96- @pytest .mark .asyncio
9793 async def test_upload_different_file_types (self , files_provider , sample_text_file , sample_json_file , large_file ):
9894 """Test uploading different types and sizes of files."""
9995 files_to_test = [
@@ -107,7 +103,6 @@ async def test_upload_different_file_types(self, files_provider, sample_text_fil
107103 assert result .filename == expected_filename
108104 assert result .bytes == len (file_obj .content )
109105
110- @pytest .mark .asyncio
111106 async def test_list_files_empty (self , files_provider ):
112107 """Test listing files when no files exist."""
113108 result = await files_provider .openai_list_files ()
@@ -117,7 +112,6 @@ async def test_list_files_empty(self, files_provider):
117112 assert result .first_id == ""
118113 assert result .last_id == ""
119114
120- @pytest .mark .asyncio
121115 async def test_list_files_with_content (self , files_provider , sample_text_file , sample_json_file ):
122116 """Test listing files when files exist."""
123117 # Upload multiple files
@@ -132,7 +126,6 @@ async def test_list_files_with_content(self, files_provider, sample_text_file, s
132126 assert file1 .id in file_ids
133127 assert file2 .id in file_ids
134128
135- @pytest .mark .asyncio
136129 async def test_list_files_with_purpose_filter (self , files_provider , sample_text_file ):
137130 """Test listing files with purpose filtering."""
138131 # Upload file with specific purpose
@@ -146,7 +139,6 @@ async def test_list_files_with_purpose_filter(self, files_provider, sample_text_
146139 assert result .data [0 ].id == uploaded_file .id
147140 assert result .data [0 ].purpose == OpenAIFilePurpose .ASSISTANTS
148141
149- @pytest .mark .asyncio
150142 async def test_list_files_with_limit (self , files_provider , sample_text_file ):
151143 """Test listing files with limit parameter."""
152144 # Upload multiple files
@@ -157,7 +149,6 @@ async def test_list_files_with_limit(self, files_provider, sample_text_file):
157149 result = await files_provider .openai_list_files (limit = 3 )
158150 assert len (result .data ) == 3
159151
160- @pytest .mark .asyncio
161152 async def test_list_files_with_order (self , files_provider , sample_text_file ):
162153 """Test listing files with different order."""
163154 # Upload multiple files
@@ -178,7 +169,6 @@ async def test_list_files_with_order(self, files_provider, sample_text_file):
178169 # Oldest should be first
179170 assert result_asc .data [0 ].created_at <= result_asc .data [1 ].created_at <= result_asc .data [2 ].created_at
180171
181- @pytest .mark .asyncio
182172 async def test_retrieve_file_success (self , files_provider , sample_text_file ):
183173 """Test successful file retrieval."""
184174 # Upload file
@@ -197,13 +187,11 @@ async def test_retrieve_file_success(self, files_provider, sample_text_file):
197187 assert retrieved_file .created_at == uploaded_file .created_at
198188 assert retrieved_file .expires_at == uploaded_file .expires_at
199189
200- @pytest .mark .asyncio
201190 async def test_retrieve_file_not_found (self , files_provider ):
202191 """Test retrieving a non-existent file."""
203192 with pytest .raises (ValueError , match = "File with id file-nonexistent not found" ):
204193 await files_provider .openai_retrieve_file ("file-nonexistent" )
205194
206- @pytest .mark .asyncio
207195 async def test_retrieve_file_content_success (self , files_provider , sample_text_file ):
208196 """Test successful file content retrieval."""
209197 # Upload file
@@ -217,13 +205,11 @@ async def test_retrieve_file_content_success(self, files_provider, sample_text_f
217205 # Verify content
218206 assert content .body == sample_text_file .content
219207
220- @pytest .mark .asyncio
221208 async def test_retrieve_file_content_not_found (self , files_provider ):
222209 """Test retrieving content of a non-existent file."""
223210 with pytest .raises (ValueError , match = "File with id file-nonexistent not found" ):
224211 await files_provider .openai_retrieve_file_content ("file-nonexistent" )
225212
226- @pytest .mark .asyncio
227213 async def test_delete_file_success (self , files_provider , sample_text_file ):
228214 """Test successful file deletion."""
229215 # Upload file
@@ -245,13 +231,11 @@ async def test_delete_file_success(self, files_provider, sample_text_file):
245231 with pytest .raises (ValueError , match = f"File with id { uploaded_file .id } not found" ):
246232 await files_provider .openai_retrieve_file (uploaded_file .id )
247233
248- @pytest .mark .asyncio
249234 async def test_delete_file_not_found (self , files_provider ):
250235 """Test deleting a non-existent file."""
251236 with pytest .raises (ValueError , match = "File with id file-nonexistent not found" ):
252237 await files_provider .openai_delete_file ("file-nonexistent" )
253238
254- @pytest .mark .asyncio
255239 async def test_file_persistence_across_operations (self , files_provider , sample_text_file ):
256240 """Test that files persist correctly across multiple operations."""
257241 # Upload file
@@ -279,7 +263,6 @@ async def test_file_persistence_across_operations(self, files_provider, sample_t
279263 files_list = await files_provider .openai_list_files ()
280264 assert len (files_list .data ) == 0
281265
282- @pytest .mark .asyncio
283266 async def test_multiple_files_operations (self , files_provider , sample_text_file , sample_json_file ):
284267 """Test operations with multiple files."""
285268 # Upload multiple files
@@ -302,7 +285,6 @@ async def test_multiple_files_operations(self, files_provider, sample_text_file,
302285 content = await files_provider .openai_retrieve_file_content (file2 .id )
303286 assert content .body == sample_json_file .content
304287
305- @pytest .mark .asyncio
306288 async def test_file_id_uniqueness (self , files_provider , sample_text_file ):
307289 """Test that each uploaded file gets a unique ID."""
308290 file_ids = set ()
@@ -316,7 +298,6 @@ async def test_file_id_uniqueness(self, files_provider, sample_text_file):
316298 file_ids .add (uploaded_file .id )
317299 assert uploaded_file .id .startswith ("file-" )
318300
319- @pytest .mark .asyncio
320301 async def test_file_no_filename_handling (self , files_provider ):
321302 """Test handling files with no filename."""
322303 file_without_name = MockUploadFile (b"content" , None ) # No filename
@@ -327,7 +308,6 @@ async def test_file_no_filename_handling(self, files_provider):
327308
328309 assert uploaded_file .filename == "uploaded_file" # Default filename
329310
330- @pytest .mark .asyncio
331311 async def test_after_pagination_works (self , files_provider , sample_text_file ):
332312 """Test that 'after' pagination works correctly."""
333313 # Upload multiple files to test pagination
0 commit comments