Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.13] gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings (GH-128726) #128935

Draft
wants to merge 1 commit into
base: 3.13
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ def _add_ci_python_opts(self, python_opts, keep_environ):
if not sys.stdout.write_through:
python_opts.append('-u')

# Add warnings filter 'default'
# Add warnings filter 'error'
if 'default' not in sys.warnoptions:
python_opts.extend(('-W', 'default'))
python_opts.extend(('-W', 'error'))

# Error on bytes/str comparison
if sys.flags.bytes_warning < 2:
Expand Down
31 changes: 15 additions & 16 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,22 +1324,21 @@ def test_readline_history_file(self):
if readline.backend != "editline":
self.skipTest("GNU readline is not affected by this issue")

hfile = tempfile.NamedTemporaryFile()
self.addCleanup(unlink, hfile.name)
env = os.environ.copy()
env["PYTHON_HISTORY"] = hfile.name

env["PYTHON_BASIC_REPL"] = "1"
output, exit_code = self.run_repl("spam \nexit()\n", env=env)
self.assertEqual(exit_code, 0)
self.assertIn("spam ", output)
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())

env.pop("PYTHON_BASIC_REPL", None)
output, exit_code = self.run_repl("exit\n", env=env)
self.assertEqual(exit_code, 0)
self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
with tempfile.NamedTemporaryFile() as hfile:
env = os.environ.copy()
env["PYTHON_HISTORY"] = hfile.name

env["PYTHON_BASIC_REPL"] = "1"
output, exit_code = self.run_repl("spam \nexit()\n", env=env)
self.assertEqual(exit_code, 0)
self.assertIn("spam ", output)
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())

env.pop("PYTHON_BASIC_REPL", None)
output, exit_code = self.run_repl("exit\n", env=env)
self.assertEqual(exit_code, 0)
self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())

def test_keyboard_interrupt_after_isearch(self):
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])
Expand Down
38 changes: 30 additions & 8 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest
import warnings
from test import support
from test.support import (
is_apple, os_helper, refleak_helper, socket_helper, threading_helper
is_apple, os_helper, refleak_helper, socket_helper, threading_helper,
)
import _thread as thread
import array
Expand Down Expand Up @@ -199,6 +200,24 @@ def socket_setdefaulttimeout(timeout):
socket.setdefaulttimeout(old_timeout)


@contextlib.contextmanager
def downgrade_malformed_data_warning():
# This warning happens on macos and win, but does not always happen on linux.
if sys.platform not in {"win32", "darwin"}:
yield
return

with warnings.catch_warnings():
# TODO: gh-110012, we should investigate why this warning is happening
# and fix it properly.
warnings.filterwarnings(
action="always",
message=r"received malformed or improperly-truncated ancillary data",
category=RuntimeWarning,
)
yield


HAVE_SOCKET_CAN = _have_socket_can()

HAVE_SOCKET_CAN_ISOTP = _have_socket_can_isotp()
Expand Down Expand Up @@ -3941,8 +3960,9 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0):
# mindata and maxdata bytes when received with buffer size
# ancbuf, and that any complete file descriptor numbers are
# valid.
msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
len(MSG), ancbuf)
with downgrade_malformed_data_warning(): # TODO: gh-110012
msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
len(MSG), ancbuf)
self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC)
Expand Down Expand Up @@ -4293,8 +4313,9 @@ def testSingleCmsgTruncInData(self):
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
socket.IPV6_RECVHOPLIMIT, 1)
self.misc_event.set()
msg, ancdata, flags, addr = self.doRecvmsg(
self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)
with downgrade_malformed_data_warning(): # TODO: gh-110012
msg, ancdata, flags, addr = self.doRecvmsg(
self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)

self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
Expand Down Expand Up @@ -4397,9 +4418,10 @@ def testSecondCmsgTruncInData(self):
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
socket.IPV6_RECVTCLASS, 1)
self.misc_event.set()
msg, ancdata, flags, addr = self.doRecvmsg(
self.serv_sock, len(MSG),
socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)
with downgrade_malformed_data_warning(): # TODO: gh-110012
msg, ancdata, flags, addr = self.doRecvmsg(
self.serv_sock, len(MSG),
socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)

self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
Expand Down
Loading