Skip to content

Commit

Permalink
Merge PR aio-libs#6872
Browse files Browse the repository at this point in the history
This change updates the pytest configuration to defeat the
unintentional resource leaks caused by an incorrect method of
suppressing the `PytestUnraisableExceptionWarning`s.

Contributed by Thomas Grainger.
  • Loading branch information
webknjaz committed Aug 8, 2022
2 parents 013e45f + d911fa7 commit 799dc87
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGES/6872.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed suppression of :py:class:`ResourceWarning`s in the pytest setup -- by :user:`graingert`.
10 changes: 5 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ addopts =
filterwarnings =
error
ignore:module 'ssl' has no attribute 'OP_NO_COMPRESSION'. The Python interpreter is compiled against OpenSSL < 1.0.0. Ref. https.//docs.python.org/3/library/ssl.html#ssl.OP_NO_COMPRESSION:UserWarning
ignore:Exception ignored in. <function _SSLProtocolTransport.__del__ at.:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception
ignore:Exception ignored in. <coroutine object BaseConnector.close at 0x.:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception
ignore:Exception ignored in. <coroutine object ClientSession._request at 0x.:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception
ignore:Exception ignored in. <function ClientSession.__del__ at 0x.:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception
ignore:Exception ignored in. <_io.FileIO .closed.>:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception
ignore:unclosed transport <asyncio.sslproto._SSLProtocolTransport object at 0x.*:ResourceWarning
ignore:coroutine 'BaseConnector.close' was never awaited:RuntimeWarning
ignore:coroutine 'ClientSession._request' was never awaited:RuntimeWarning
ignore:Unclosed client session <aiohttp.client.ClientSession object at 0x:ResourceWarning
ignore:unclosed file <_io.FileIO.*:ResourceWarning
ignore:The loop argument is deprecated:DeprecationWarning:asyncio
ignore:Creating a LegacyVersion has been deprecated and will be removed in the next major release:DeprecationWarning::
# The following deprecation warning is triggered by importing
Expand Down
22 changes: 11 additions & 11 deletions tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@

_has_unix_domain_socks = hasattr(socket, "AF_UNIX")
if _has_unix_domain_socks:
_abstract_path_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
_abstract_path_sock.bind(b"\x00" + uuid4().hex.encode("ascii"))
except FileNotFoundError:
_abstract_path_failed = True
else:
_abstract_path_failed = False
finally:
_abstract_path_sock.close()
del _abstract_path_sock
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as _abstract_path_sock:
try:
_abstract_path_sock.bind(b"\x00" + uuid4().hex.encode("ascii"))
except FileNotFoundError:
_abstract_path_failed = True
else:
_abstract_path_failed = False
finally:
del _abstract_path_sock
else:
_abstract_path_failed = True

Expand All @@ -48,7 +47,8 @@
# support, but the target system still may not have it.
# So let's ensure that we really have IPv6 support.
try:
socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM):
pass
except OSError:
HAS_IPV6 = False

Expand Down
3 changes: 2 additions & 1 deletion tests/test_tcp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# support, but the target system still may not have it.
# So let's ensure that we really have IPv6 support.
try:
socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM):
pass
except OSError:
has_ipv6 = False

Expand Down

0 comments on commit 799dc87

Please sign in to comment.