@@ -189,37 +189,37 @@ class PackageQuestion(Question):
189
189
return QuestionTypeWrapper (PackageQuestion , package )
190
190
191
191
192
- async def _assert_graceful_shutdown (pkg_location : PackageLocation , storage_path : Path , port : int ) -> None :
193
- async with WebServer (pkg_location , state_storage_path = storage_path , port = port ):
194
- await asyncio .sleep (0 )
195
-
196
- pending = [t for t in asyncio .all_tasks () if t is not asyncio .current_task () and not t .done ()]
197
- if pending :
198
- pending_tasks_display = "\n " .join (f" - { t } " for t in pending )
199
- for task in pending :
200
- task .cancel ()
201
- await asyncio .gather (* pending , return_exceptions = True )
202
- pytest .fail (f"Pending tasks after shutdown:\n { pending_tasks_display } " )
192
+ @pytest .fixture
193
+ def function_pkg_location () -> FunctionPackageLocation :
194
+ return FunctionPackageLocation .from_function (_pkg_init )
203
195
204
196
205
- @pytest .mark .asyncio (loop_scope = "function" )
206
- async def test_webserver_shutdown_function (tmp_path : Path , port : int ) -> None :
207
- pkg_location = FunctionPackageLocation .from_function (_pkg_init )
197
+ @pytest .fixture
198
+ def dir_pkg_location (source_path : Path ) -> DirPackageLocation :
199
+ with DirPackageBuilder (PackageSource (source_path )) as builder :
200
+ builder .write_package ()
201
+ return DirPackageLocation (source_path / DIST_DIR )
208
202
209
- await _assert_graceful_shutdown (pkg_location , tmp_path , port )
210
203
204
+ @pytest .fixture
205
+ def zip_pkg_location (qpy_pkg_path : Path ) -> ZipPackageLocation :
206
+ return ZipPackageLocation (qpy_pkg_path , calculate_hash (qpy_pkg_path ))
211
207
212
- @pytest .mark .asyncio (loop_scope = "function" )
213
- async def test_webserver_shutdown_dir (tmp_path : Path , port : int , source_path : Path ) -> None :
214
- with DirPackageBuilder (PackageSource (source_path )) as builder :
215
- builder .write_package ()
216
- pkg_location = DirPackageLocation (source_path / DIST_DIR )
217
208
218
- await _assert_graceful_shutdown (pkg_location , tmp_path , port )
209
+ @pytest .fixture (params = ["function_pkg_location" , "dir_pkg_location" , "zip_pkg_location" ])
210
+ def pkg_location (request : pytest .FixtureRequest ) -> PackageLocation :
211
+ return request .getfixturevalue (request .param )
219
212
220
213
221
214
@pytest .mark .asyncio (loop_scope = "function" )
222
- async def test_webserver_shutdown_zip (tmp_path : Path , port : int , qpy_pkg_path : Path ) -> None :
223
- pkg_location = ZipPackageLocation (qpy_pkg_path , calculate_hash (qpy_pkg_path ))
215
+ async def test_webserver_graceful_shutdown (pkg_location : PackageLocation , tmp_path : Path , port : int ) -> None :
216
+ async with WebServer (pkg_location , state_storage_path = tmp_path , port = port ):
217
+ await asyncio .sleep (0 )
224
218
225
- await _assert_graceful_shutdown (pkg_location , tmp_path , port )
219
+ pending = [t for t in asyncio .all_tasks () if t is not asyncio .current_task () and not t .done ()]
220
+ if pending :
221
+ pending_tasks_display = "\n " .join (f" - { t } " for t in pending )
222
+ for task in pending :
223
+ task .cancel ()
224
+ await asyncio .gather (* pending , return_exceptions = True )
225
+ pytest .fail (f"Pending tasks after shutdown:\n { pending_tasks_display } " )
0 commit comments