Skip to content

Commit a6bb15e

Browse files
committed
Reapply "pythongh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings (python#128726)" (python#128936)
This reverts commit 76856ae.
1 parent 9ed7bf2 commit a6bb15e

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

Lib/test/libregrtest/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,9 @@ def _add_ci_python_opts(self, python_opts, keep_environ):
642642
if not sys.stdout.write_through:
643643
python_opts.append('-u')
644644

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

649649
# Error on bytes/str comparison
650650
if sys.flags.bytes_warning < 2:

Lib/test/test_pyrepl/test_pyrepl.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -1324,22 +1324,21 @@ def test_readline_history_file(self):
13241324
if readline.backend != "editline":
13251325
self.skipTest("GNU readline is not affected by this issue")
13261326

1327-
hfile = tempfile.NamedTemporaryFile()
1328-
self.addCleanup(unlink, hfile.name)
1329-
env = os.environ.copy()
1330-
env["PYTHON_HISTORY"] = hfile.name
1331-
1332-
env["PYTHON_BASIC_REPL"] = "1"
1333-
output, exit_code = self.run_repl("spam \nexit()\n", env=env)
1334-
self.assertEqual(exit_code, 0)
1335-
self.assertIn("spam ", output)
1336-
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
1337-
self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
1338-
1339-
env.pop("PYTHON_BASIC_REPL", None)
1340-
output, exit_code = self.run_repl("exit\n", env=env)
1341-
self.assertEqual(exit_code, 0)
1342-
self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
1327+
with tempfile.NamedTemporaryFile() as hfile:
1328+
env = os.environ.copy()
1329+
env["PYTHON_HISTORY"] = hfile.name
1330+
1331+
env["PYTHON_BASIC_REPL"] = "1"
1332+
output, exit_code = self.run_repl("spam \nexit()\n", env=env)
1333+
self.assertEqual(exit_code, 0)
1334+
self.assertIn("spam ", output)
1335+
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
1336+
self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
1337+
1338+
env.pop("PYTHON_BASIC_REPL", None)
1339+
output, exit_code = self.run_repl("exit\n", env=env)
1340+
self.assertEqual(exit_code, 0)
1341+
self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
13431342

13441343
def test_keyboard_interrupt_after_isearch(self):
13451344
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])

Lib/test/test_socket.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import unittest
2+
import warnings
23
from test import support
34
from test.support import (
4-
is_apple, os_helper, refleak_helper, socket_helper, threading_helper
5+
is_apple, os_helper, refleak_helper, socket_helper, threading_helper,
56
)
67
import _thread as thread
78
import array
@@ -198,6 +199,24 @@ def socket_setdefaulttimeout(timeout):
198199
socket.setdefaulttimeout(old_timeout)
199200

200201

202+
@contextlib.contextmanager
203+
def downgrade_malformed_data_warning():
204+
# This warning happens on macos and win, but does not always happen on linux.
205+
if sys.platform not in {"win32", "darwin"}:
206+
yield
207+
return
208+
209+
with warnings.catch_warnings():
210+
# TODO: gh-110012, we should investigate why this warning is happening
211+
# and fix it properly.
212+
warnings.filterwarnings(
213+
action="always",
214+
message=r"received malformed or improperly-truncated ancillary data",
215+
category=RuntimeWarning,
216+
)
217+
yield
218+
219+
201220
HAVE_SOCKET_CAN = _have_socket_can()
202221

203222
HAVE_SOCKET_CAN_ISOTP = _have_socket_can_isotp()
@@ -3946,8 +3965,9 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0):
39463965
# mindata and maxdata bytes when received with buffer size
39473966
# ancbuf, and that any complete file descriptor numbers are
39483967
# valid.
3949-
msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
3950-
len(MSG), ancbuf)
3968+
with downgrade_malformed_data_warning(): # TODO: gh-110012
3969+
msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
3970+
len(MSG), ancbuf)
39513971
self.assertEqual(msg, MSG)
39523972
self.checkRecvmsgAddress(addr, self.cli_addr)
39533973
self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC)
@@ -4298,8 +4318,9 @@ def testSingleCmsgTruncInData(self):
42984318
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
42994319
socket.IPV6_RECVHOPLIMIT, 1)
43004320
self.misc_event.set()
4301-
msg, ancdata, flags, addr = self.doRecvmsg(
4302-
self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)
4321+
with downgrade_malformed_data_warning(): # TODO: gh-110012
4322+
msg, ancdata, flags, addr = self.doRecvmsg(
4323+
self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)
43034324

43044325
self.assertEqual(msg, MSG)
43054326
self.checkRecvmsgAddress(addr, self.cli_addr)
@@ -4402,9 +4423,10 @@ def testSecondCmsgTruncInData(self):
44024423
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
44034424
socket.IPV6_RECVTCLASS, 1)
44044425
self.misc_event.set()
4405-
msg, ancdata, flags, addr = self.doRecvmsg(
4406-
self.serv_sock, len(MSG),
4407-
socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)
4426+
with downgrade_malformed_data_warning(): # TODO: gh-110012
4427+
msg, ancdata, flags, addr = self.doRecvmsg(
4428+
self.serv_sock, len(MSG),
4429+
socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)
44084430

44094431
self.assertEqual(msg, MSG)
44104432
self.checkRecvmsgAddress(addr, self.cli_addr)

0 commit comments

Comments
 (0)