22import threading
33import time
44from unittest import mock
5- import unittest
65import pytest
76try :
87 from engineio .async_socket import AsyncSocket as EngineIOSocket
@@ -38,13 +37,13 @@ def connect(sid, environ, auth):
3837 pass
3938
4039 async def shutdown ():
41- await instrumented_server .shutdown ()
40+ await self . isvr .shutdown ()
4241 await sio .shutdown ()
4342
4443 if 'server_stats_interval' not in ikwargs :
4544 ikwargs ['server_stats_interval' ] = 0.25
4645
47- instrumented_server = sio .instrument (auth = auth , ** ikwargs )
46+ self . isvr = sio .instrument (auth = auth , ** ikwargs )
4847 server = SocketIOWebServer (sio , on_shutdown = shutdown )
4948 server .start ()
5049
@@ -56,10 +55,11 @@ async def shutdown():
5655 EngineIOSocket .schedule_ping = mock .MagicMock ()
5756
5857 try :
59- ret = f (self , instrumented_server , * args , ** kwargs )
58+ ret = f (self , * args , ** kwargs )
6059 finally :
6160 server .stop ()
62- instrumented_server .uninstrument ()
61+ self .isvr .uninstrument ()
62+ self .isvr = None
6363
6464 EngineIOSocket .schedule_ping = original_schedule_ping
6565
@@ -80,12 +80,12 @@ async def _async_custom_auth(auth):
8080 return auth == {'foo' : 'bar' }
8181
8282
83- class TestAsyncAdmin ( unittest . TestCase ) :
84- def setUp (self ):
83+ class TestAsyncAdmin :
84+ def setup_method (self ):
8585 print ('threads at start:' , threading .enumerate ())
8686 self .thread_count = threading .active_count ()
8787
88- def tearDown (self ):
88+ def teardown_method (self ):
8989 print ('threads at end:' , threading .enumerate ())
9090 assert self .thread_count == threading .active_count ()
9191
@@ -107,15 +107,15 @@ def test_missing_auth(self):
107107 sio .instrument ()
108108
109109 @with_instrumented_server (auth = False )
110- def test_admin_connect_with_no_auth (self , isvr ):
110+ def test_admin_connect_with_no_auth (self ):
111111 with socketio .SimpleClient () as admin_client :
112112 admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
113113 with socketio .SimpleClient () as admin_client :
114114 admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
115115 auth = {'foo' : 'bar' })
116116
117117 @with_instrumented_server (auth = {'foo' : 'bar' })
118- def test_admin_connect_with_dict_auth (self , isvr ):
118+ def test_admin_connect_with_dict_auth (self ):
119119 with socketio .SimpleClient () as admin_client :
120120 admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
121121 auth = {'foo' : 'bar' })
@@ -131,7 +131,7 @@ def test_admin_connect_with_dict_auth(self, isvr):
131131
132132 @with_instrumented_server (auth = [{'foo' : 'bar' },
133133 {'u' : 'admin' , 'p' : 'secret' }])
134- def test_admin_connect_with_list_auth (self , isvr ):
134+ def test_admin_connect_with_list_auth (self ):
135135 with socketio .SimpleClient () as admin_client :
136136 admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
137137 auth = {'foo' : 'bar' })
@@ -148,7 +148,7 @@ def test_admin_connect_with_list_auth(self, isvr):
148148 namespace = '/admin' )
149149
150150 @with_instrumented_server (auth = _custom_auth )
151- def test_admin_connect_with_function_auth (self , isvr ):
151+ def test_admin_connect_with_function_auth (self ):
152152 with socketio .SimpleClient () as admin_client :
153153 admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
154154 auth = {'foo' : 'bar' })
@@ -162,7 +162,7 @@ def test_admin_connect_with_function_auth(self, isvr):
162162 namespace = '/admin' )
163163
164164 @with_instrumented_server (auth = _async_custom_auth )
165- def test_admin_connect_with_async_function_auth (self , isvr ):
165+ def test_admin_connect_with_async_function_auth (self ):
166166 with socketio .SimpleClient () as admin_client :
167167 admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
168168 auth = {'foo' : 'bar' })
@@ -176,7 +176,7 @@ def test_admin_connect_with_async_function_auth(self, isvr):
176176 namespace = '/admin' )
177177
178178 @with_instrumented_server ()
179- def test_admin_connect_only_admin (self , isvr ):
179+ def test_admin_connect_only_admin (self ):
180180 with socketio .SimpleClient () as admin_client :
181181 admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
182182 sid = admin_client .sid
@@ -201,7 +201,7 @@ def test_admin_connect_only_admin(self, isvr):
201201 events ['server_stats' ]['namespaces' ]
202202
203203 @with_instrumented_server ()
204- def test_admin_connect_with_others (self , isvr ):
204+ def test_admin_connect_with_others (self ):
205205 with socketio .SimpleClient () as client1 , \
206206 socketio .SimpleClient () as client2 , \
207207 socketio .SimpleClient () as client3 , \
@@ -210,12 +210,12 @@ def test_admin_connect_with_others(self, isvr):
210210 client1 .emit ('enter_room' , 'room' )
211211 sid1 = client1 .sid
212212
213- saved_check_for_upgrade = isvr ._check_for_upgrade
214- isvr ._check_for_upgrade = AsyncMock ()
213+ saved_check_for_upgrade = self . isvr ._check_for_upgrade
214+ self . isvr ._check_for_upgrade = AsyncMock ()
215215 client2 .connect ('http://localhost:8900' , namespace = '/foo' ,
216216 transports = ['polling' ])
217217 sid2 = client2 .sid
218- isvr ._check_for_upgrade = saved_check_for_upgrade
218+ self . isvr ._check_for_upgrade = saved_check_for_upgrade
219219
220220 client3 .connect ('http://localhost:8900' , namespace = '/admin' )
221221 sid3 = client3 .sid
@@ -251,7 +251,7 @@ def test_admin_connect_with_others(self, isvr):
251251 assert socket ['rooms' ] == [sid3 ]
252252
253253 @with_instrumented_server (mode = 'production' , read_only = True )
254- def test_admin_connect_production (self , isvr ):
254+ def test_admin_connect_production (self ):
255255 with socketio .SimpleClient () as admin_client :
256256 admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
257257 events = self ._expect ({'config' : 1 , 'server_stats' : 2 },
@@ -272,7 +272,7 @@ def test_admin_connect_production(self, isvr):
272272 events ['server_stats' ]['namespaces' ]
273273
274274 @with_instrumented_server ()
275- def test_admin_features (self , isvr ):
275+ def test_admin_features (self ):
276276 with socketio .SimpleClient () as client1 , \
277277 socketio .SimpleClient () as client2 , \
278278 socketio .SimpleClient () as admin_client :
0 commit comments