1919from websockets .protocol import CLIENT , SERVER , Protocol , State
2020
2121from ..protocol import RecordingProtocol
22- from ..utils import MS
22+ from ..utils import MS , AssertNoLogsMixin
2323from .connection import InterceptingConnection
2424from .utils import alist
2525
2828# All tests run on the client side and the server side to validate this.
2929
3030
31- class ClientConnectionTests (unittest .IsolatedAsyncioTestCase ):
31+ class ClientConnectionTests (AssertNoLogsMixin , unittest .IsolatedAsyncioTestCase ):
3232 LOCAL = CLIENT
3333 REMOTE = SERVER
3434
@@ -48,23 +48,6 @@ async def asyncTearDown(self):
4848 await self .remote_connection .close ()
4949 await self .connection .close ()
5050
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-
6851 # Test helpers built upon RecordingProtocol and InterceptingConnection.
6952
7053 async def assertFrameSent (self , frame ):
@@ -1277,7 +1260,7 @@ async def test_broadcast_skips_closed_connection(self):
12771260 await self .connection .close ()
12781261 await self .assertFrameSent (Frame (Opcode .CLOSE , b"\x03 \xe8 " ))
12791262
1280- with self .assertNoLogs ():
1263+ with self .assertNoLogs ("websockets" , logging . WARNING ):
12811264 broadcast ([self .connection ], "😀" )
12821265 await self .assertNoFrameSent ()
12831266
@@ -1288,7 +1271,7 @@ async def test_broadcast_skips_closing_connection(self):
12881271 await asyncio .sleep (0 )
12891272 await self .assertFrameSent (Frame (Opcode .CLOSE , b"\x03 \xe8 " ))
12901273
1291- with self .assertNoLogs ():
1274+ with self .assertNoLogs ("websockets" , logging . WARNING ):
12921275 broadcast ([self .connection ], "😀" )
12931276 await self .assertNoFrameSent ()
12941277
0 commit comments