Skip to content

Commit

Permalink
Clean deprecation warnings in test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Oct 8, 2022
1 parent a899d5a commit 15791c5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
12 changes: 10 additions & 2 deletions tests/legacy/test_client_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ async def start_server():
return await serve(handler, "localhost", 0, **kwargs)

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

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

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

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

with contextlib.closing(response):
Expand Down Expand Up @@ -563,6 +566,7 @@ def process_request(self, path, request_headers):
@with_server(create_protocol=LegacyProcessRequestOKServerProtocol)
def test_process_request_override_backwards_compatibility(self):
with warnings.catch_warnings(record=True) as recorded_warnings:
warnings.simplefilter("always")
response = self.loop.run_until_complete(self.make_http_request("/"))

with contextlib.closing(response):
Expand Down Expand Up @@ -607,6 +611,7 @@ def test_protocol_deprecated_attributes(self):
for server_socket in self.server.sockets
]
with warnings.catch_warnings(record=True) as recorded_warnings:
warnings.simplefilter("always")
client_attrs = (self.client.host, self.client.port, self.client.secure)
self.assertDeprecationWarnings(
recorded_warnings,
Expand All @@ -620,6 +625,7 @@ def test_protocol_deprecated_attributes(self):

expected_server_attrs = ("localhost", 0, self.secure)
with warnings.catch_warnings(record=True) as recorded_warnings:
warnings.simplefilter("always")
self.loop.run_until_complete(self.client.send(""))
server_attrs = self.loop.run_until_complete(self.client.recv())
self.assertDeprecationWarnings(
Expand Down Expand Up @@ -1356,7 +1362,8 @@ class YieldFromTests(ClientServerTestsMixin, AsyncioTestCase):
@with_server()
def test_client(self):
# @asyncio.coroutine is deprecated on Python ≥ 3.8
with warnings.catch_warnings(record=True):
with warnings.catch_warnings():
warnings.simplefilter("ignore")

@asyncio.coroutine
def run_client():
Expand All @@ -1370,7 +1377,8 @@ def run_client():

def test_server(self):
# @asyncio.coroutine is deprecated on Python ≥ 3.8
with warnings.catch_warnings(record=True):
with warnings.catch_warnings():
warnings.simplefilter("ignore")

@asyncio.coroutine
def run_server():
Expand Down
6 changes: 4 additions & 2 deletions tests/legacy/test_framing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def decode(self, message, mask=False, max_size=None, extensions=None):
stream = asyncio.StreamReader(loop=self.loop)
stream.feed_data(message)
stream.feed_eof()
with warnings.catch_warnings(record=True):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
frame = self.loop.run_until_complete(
Frame.read(
stream.readexactly,
Expand All @@ -32,7 +33,8 @@ def decode(self, message, mask=False, max_size=None, extensions=None):

def encode(self, frame, mask=False, extensions=None):
write = unittest.mock.Mock()
with warnings.catch_warnings(record=True):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
frame.write(write, mask=mask, extensions=extensions)
# Ensure the entire frame is sent with a single call to write().
# Multiple calls cause TCP fragmentation and degrade performance.
Expand Down
2 changes: 2 additions & 0 deletions tests/legacy/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ async def create_protocol():
return WebSocketCommonProtocol(ping_interval=None, timeout=5)

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

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

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

self.assertEqual(protocol.loop, loop)
Expand Down
1 change: 1 addition & 0 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_get_deprecated_alias(self):
)

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

self.assertEqual(len(recorded_warnings), 1)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
envlist = py37,py38,py39,py310,coverage,black,flake8,isort,mypy

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

[testenv:coverage]
commands =
Expand Down

0 comments on commit 15791c5

Please sign in to comment.