19
19
from websockets .protocol import CLIENT , SERVER , Protocol , State
20
20
21
21
from ..protocol import RecordingProtocol
22
- from ..utils import MS
22
+ from ..utils import MS , AssertNoLogsMixin
23
23
from .connection import InterceptingConnection
24
24
from .utils import alist
25
25
28
28
# All tests run on the client side and the server side to validate this.
29
29
30
30
31
- class ClientConnectionTests (unittest .IsolatedAsyncioTestCase ):
31
+ class ClientConnectionTests (AssertNoLogsMixin , unittest .IsolatedAsyncioTestCase ):
32
32
LOCAL = CLIENT
33
33
REMOTE = SERVER
34
34
@@ -48,23 +48,6 @@ async def asyncTearDown(self):
48
48
await self .remote_connection .close ()
49
49
await self .connection .close ()
50
50
51
- if sys .version_info [:2 ] < (3 , 10 ): # pragma: no cover
52
-
53
- @contextlib .contextmanager
54
- def assertNoLogs (self , logger = None , level = None ):
55
- """
56
- No message is logged on the given logger with at least the given level.
57
-
58
- """
59
- with self .assertLogs (logger , level ) as logs :
60
- # We want to test that no log message is emitted
61
- # but assertLogs expects at least one log message.
62
- logging .getLogger (logger ).log (level , "dummy" )
63
- yield
64
-
65
- level_name = logging .getLevelName (level )
66
- self .assertEqual (logs .output , [f"{ level_name } :{ logger } :dummy" ])
67
-
68
51
# Test helpers built upon RecordingProtocol and InterceptingConnection.
69
52
70
53
async def assertFrameSent (self , frame ):
@@ -1277,7 +1260,7 @@ async def test_broadcast_skips_closed_connection(self):
1277
1260
await self .connection .close ()
1278
1261
await self .assertFrameSent (Frame (Opcode .CLOSE , b"\x03 \xe8 " ))
1279
1262
1280
- with self .assertNoLogs ():
1263
+ with self .assertNoLogs ("websockets" , logging . WARNING ):
1281
1264
broadcast ([self .connection ], "😀" )
1282
1265
await self .assertNoFrameSent ()
1283
1266
@@ -1288,7 +1271,7 @@ async def test_broadcast_skips_closing_connection(self):
1288
1271
await asyncio .sleep (0 )
1289
1272
await self .assertFrameSent (Frame (Opcode .CLOSE , b"\x03 \xe8 " ))
1290
1273
1291
- with self .assertNoLogs ():
1274
+ with self .assertNoLogs ("websockets" , logging . WARNING ):
1292
1275
broadcast ([self .connection ], "😀" )
1293
1276
await self .assertNoFrameSent ()
1294
1277
0 commit comments