From 3e02938e45e4276fbd83f8c2fff4bb882a0e1e51 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sat, 6 Aug 2022 08:57:27 +0100 Subject: [PATCH 1/4] ignore the ResourceWarnings before they become unraisable exceptions --- setup.cfg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 6a8649ada69..9f8fc199537 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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. :pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception + ignore:unclosed transport <_SSLProtocolTransport.*:ResourceWarning + ignore:coroutine 'BaseConnector.close' was never awaited:RuntimeWarning + ignore:coroutine 'ClientSession._request' was never awaited:RuntimeWarning + ignore:Unclosed client session Date: Sat, 6 Aug 2022 09:09:35 +0100 Subject: [PATCH 2/4] Update setup.cfg --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 9f8fc199537..f5918ff6a28 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,7 +132,7 @@ 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:unclosed transport <_SSLProtocolTransport.*:ResourceWarning + ignore:unclosed transport Date: Sat, 6 Aug 2022 09:25:31 +0100 Subject: [PATCH 3/4] use context manager with sockets started before test run --- tests/test_run_app.py | 22 +++++++++++----------- tests/test_tcp_helpers.py | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/test_run_app.py b/tests/test_run_app.py index cd91d4b4282..0ef686768f6 100644 --- a/tests/test_run_app.py +++ b/tests/test_run_app.py @@ -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 @@ -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 diff --git a/tests/test_tcp_helpers.py b/tests/test_tcp_helpers.py index 2b468ba470a..74770d108d8 100644 --- a/tests/test_tcp_helpers.py +++ b/tests/test_tcp_helpers.py @@ -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 From d911fa7ad2dde3395e53b0aa9fdea89c25fe0dfa Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 8 Aug 2022 16:49:48 +0200 Subject: [PATCH 4/4] Add a change note to PR #6872 --- CHANGES/6872.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/6872.misc diff --git a/CHANGES/6872.misc b/CHANGES/6872.misc new file mode 100644 index 00000000000..6cb08c89518 --- /dev/null +++ b/CHANGES/6872.misc @@ -0,0 +1 @@ +Fixed suppression of :py:class:`ResourceWarning`s in the pytest setup -- by :user:`graingert`.