File tree 1 file changed +9
-0
lines changed
1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import copy
3
3
import ipaddress
4
+ from contextlib import ExitStack , AsyncExitStack
4
5
from typing import cast , Dict
5
6
import unittest
6
7
from pytest_httpserver import HeaderValueMatcher
@@ -333,22 +334,30 @@ def test_missing_constructor_args(self):
333
334
334
335
class TestClient (TestBaseClient ):
335
336
def setUp (self ):
337
+ self .stack = ExitStack ()
336
338
self .client_class = Client
337
339
self .client = Client (42 , "abcdef123456" )
338
340
self .client ._base_uri = self .httpserver .url_for ("/geoip/v2.1" )
341
+ self .stack .enter_context (self .client )
342
+
343
+ def tearDown (self ):
344
+ self .stack .close ()
339
345
340
346
def run_client (self , v ):
341
347
return v
342
348
343
349
344
350
class TestAsyncClient (TestBaseClient ):
345
351
def setUp (self ):
352
+ self .stack = AsyncExitStack ()
346
353
self ._loop = asyncio .new_event_loop ()
347
354
self .client_class = AsyncClient
348
355
self .client = AsyncClient (42 , "abcdef123456" )
349
356
self .client ._base_uri = self .httpserver .url_for ("/geoip/v2.1" )
357
+ self ._loop .run_until_complete (self .stack .enter_async_context (self .client ))
350
358
351
359
def tearDown (self ):
360
+ self ._loop .run_until_complete (self .stack .aclose ())
352
361
self ._loop .run_until_complete (self .client .close ())
353
362
self ._loop .close ()
354
363
You can’t perform that action at this time.
0 commit comments