Skip to content

Commit 15791c5

Browse files
committed
Clean deprecation warnings in test suite.
1 parent a899d5a commit 15791c5

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

tests/legacy/test_client_server.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ async def start_server():
233233
return await serve(handler, "localhost", 0, **kwargs)
234234

235235
with warnings.catch_warnings(record=True) as recorded_warnings:
236+
warnings.simplefilter("always")
236237
self.server = self.loop.run_until_complete(start_server())
237238

238239
expected_warnings = [] if deprecation_warnings is None else deprecation_warnings
@@ -259,6 +260,7 @@ async def start_client():
259260
return await connect(server_uri, **kwargs)
260261

261262
with warnings.catch_warnings(record=True) as recorded_warnings:
263+
warnings.simplefilter("always")
262264
self.client = self.loop.run_until_complete(start_client())
263265

264266
expected_warnings = [] if deprecation_warnings is None else deprecation_warnings
@@ -536,6 +538,7 @@ def legacy_process_request_OK(path, request_headers):
536538
@with_server(process_request=legacy_process_request_OK)
537539
def test_process_request_argument_backwards_compatibility(self):
538540
with warnings.catch_warnings(record=True) as recorded_warnings:
541+
warnings.simplefilter("always")
539542
response = self.loop.run_until_complete(self.make_http_request("/"))
540543

541544
with contextlib.closing(response):
@@ -563,6 +566,7 @@ def process_request(self, path, request_headers):
563566
@with_server(create_protocol=LegacyProcessRequestOKServerProtocol)
564567
def test_process_request_override_backwards_compatibility(self):
565568
with warnings.catch_warnings(record=True) as recorded_warnings:
569+
warnings.simplefilter("always")
566570
response = self.loop.run_until_complete(self.make_http_request("/"))
567571

568572
with contextlib.closing(response):
@@ -607,6 +611,7 @@ def test_protocol_deprecated_attributes(self):
607611
for server_socket in self.server.sockets
608612
]
609613
with warnings.catch_warnings(record=True) as recorded_warnings:
614+
warnings.simplefilter("always")
610615
client_attrs = (self.client.host, self.client.port, self.client.secure)
611616
self.assertDeprecationWarnings(
612617
recorded_warnings,
@@ -620,6 +625,7 @@ def test_protocol_deprecated_attributes(self):
620625

621626
expected_server_attrs = ("localhost", 0, self.secure)
622627
with warnings.catch_warnings(record=True) as recorded_warnings:
628+
warnings.simplefilter("always")
623629
self.loop.run_until_complete(self.client.send(""))
624630
server_attrs = self.loop.run_until_complete(self.client.recv())
625631
self.assertDeprecationWarnings(
@@ -1356,7 +1362,8 @@ class YieldFromTests(ClientServerTestsMixin, AsyncioTestCase):
13561362
@with_server()
13571363
def test_client(self):
13581364
# @asyncio.coroutine is deprecated on Python ≥ 3.8
1359-
with warnings.catch_warnings(record=True):
1365+
with warnings.catch_warnings():
1366+
warnings.simplefilter("ignore")
13601367

13611368
@asyncio.coroutine
13621369
def run_client():
@@ -1370,7 +1377,8 @@ def run_client():
13701377

13711378
def test_server(self):
13721379
# @asyncio.coroutine is deprecated on Python ≥ 3.8
1373-
with warnings.catch_warnings(record=True):
1380+
with warnings.catch_warnings():
1381+
warnings.simplefilter("ignore")
13741382

13751383
@asyncio.coroutine
13761384
def run_server():

tests/legacy/test_framing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def decode(self, message, mask=False, max_size=None, extensions=None):
1717
stream = asyncio.StreamReader(loop=self.loop)
1818
stream.feed_data(message)
1919
stream.feed_eof()
20-
with warnings.catch_warnings(record=True):
20+
with warnings.catch_warnings():
21+
warnings.simplefilter("ignore")
2122
frame = self.loop.run_until_complete(
2223
Frame.read(
2324
stream.readexactly,
@@ -32,7 +33,8 @@ def decode(self, message, mask=False, max_size=None, extensions=None):
3233

3334
def encode(self, frame, mask=False, extensions=None):
3435
write = unittest.mock.Mock()
35-
with warnings.catch_warnings(record=True):
36+
with warnings.catch_warnings():
37+
warnings.simplefilter("ignore")
3638
frame.write(write, mask=mask, extensions=extensions)
3739
# Ensure the entire frame is sent with a single call to write().
3840
# Multiple calls cause TCP fragmentation and degrade performance.

tests/legacy/test_protocol.py

+2
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ async def create_protocol():
322322
return WebSocketCommonProtocol(ping_interval=None, timeout=5)
323323

324324
with warnings.catch_warnings(record=True) as recorded:
325+
warnings.simplefilter("always")
325326
protocol = self.loop.run_until_complete(create_protocol())
326327

327328
self.assertEqual(protocol.close_timeout, 5)
@@ -332,6 +333,7 @@ def test_loop_backwards_compatibility(self):
332333
self.addCleanup(loop.close)
333334

334335
with warnings.catch_warnings(record=True) as recorded:
336+
warnings.simplefilter("always")
335337
protocol = WebSocketCommonProtocol(ping_interval=None, loop=loop)
336338

337339
self.assertEqual(protocol.loop, loop)

tests/test_imports.py

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_get_deprecated_alias(self):
3030
)
3131

3232
with warnings.catch_warnings(record=True) as recorded_warnings:
33+
warnings.simplefilter("always")
3334
self.assertEqual(self.mod.bar, bar)
3435

3536
self.assertEqual(len(recorded_warnings), 1)

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
envlist = py37,py38,py39,py310,coverage,black,flake8,isort,mypy
33

44
[testenv]
5-
commands = python -W default -m unittest {posargs}
5+
commands = python -W error::DeprecationWarning -W error::PendingDeprecationWarning -m unittest {posargs}
66

77
[testenv:coverage]
88
commands =

0 commit comments

Comments
 (0)