Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0d28ddd
gh-110012: Fix `RuntimeWarning` in `test_socket`
sobolevn Sep 28, 2023
da358cc
Typos!
sobolevn Sep 28, 2023
cf0cfd0
Typos!
sobolevn Sep 28, 2023
dfda254
Use `quiet=True` by default
sobolevn Sep 28, 2023
ec6a368
fix warnings in test_importlib.test_abc
graingert Jan 16, 2025
a5c2b7a
fix warnings found in test_importlib.test_windows
graingert Jan 16, 2025
0f2afcd
set warnings as errors everywhere
graingert Jan 11, 2025
8e97f04
Merge branch 'main' into issue110012
graingert Jan 16, 2025
4982ba4
Merge branch 'issue110012' into run-test-suite-with-warnings-as-error
graingert Jan 16, 2025
f45b3b8
Update test_socket.py
graingert Jan 16, 2025
0bc4c2a
Merge branch 'issue110012' into run-test-suite-with-warnings-as-error
graingert Jan 16, 2025
ca5eb67
fix ResourceWarning in test_pyrepl
graingert Jan 16, 2025
a13e948
Merge branch 'fix-resource-warning-in-test-pyrepl' into run-test-suit…
graingert Jan 16, 2025
7b2b437
downgrade rather than ignore malformed socket warning
graingert Jan 16, 2025
f2cb9b4
Merge branch 'main' into run-test-suite-with-warnings-as-error
graingert Jan 16, 2025
32cd095
Update Lib/test/test_socket.py
graingert Jan 16, 2025
db0cb51
Update Lib/test/test_socket.py
graingert Jan 16, 2025
61eb61f
Update Lib/test/test_socket.py
graingert Jan 16, 2025
91ee5ee
oops, it's not pytest
graingert Jan 16, 2025
720cca0
Merge branch 'main' into run-test-suite-with-warnings-as-error
brettcannon Jan 16, 2025
23469c3
Merge branch 'main' into run-test-suite-with-warnings-as-error
graingert Jan 17, 2025
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 @@ -642,9 +642,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
26 changes: 22 additions & 4 deletions Lib/test/test_importlib/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,15 @@ class ResourceLoaderDefaultsTests(ABCTestHarness):
SPLIT = make_abc_subclasses(ResourceLoader)

def test_get_data(self):
with self.assertRaises(IOError):
with (
self.assertRaises(IOError),
self.assertWarnsRegex(
DeprecationWarning,
r"importlib\.abc\.ResourceLoader is deprecated in favour of "
r"supporting resource loading through importlib\.resources"
r"\.abc\.TraversableResources.",
),
):
self.ins.get_data('/some/path')


Expand Down Expand Up @@ -927,9 +935,19 @@ def get_filename(self, fullname):

def path_stats(self, path):
return {'mtime': 1}

loader = DummySourceLoader()
with self.assertWarns(DeprecationWarning):
with self.assertWarnsRegex(
DeprecationWarning,
r"importlib\.abc\.ResourceLoader is deprecated in favour of "
r"supporting resource loading through importlib\.resources"
r"\.abc\.TraversableResources.",
):
loader = DummySourceLoader()

with self.assertWarnsRegex(
DeprecationWarning,
r"SourceLoader\.path_mtime is deprecated in favour of "
r"SourceLoader\.path_stats\(\)\."
):
loader.path_mtime('foo.py')


Expand Down
31 changes: 27 additions & 4 deletions Lib/test/test_importlib/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,46 @@ class WindowsRegistryFinderTests:
test_module = "spamham{}".format(os.getpid())

def test_find_spec_missing(self):
spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
with self.assertWarnsRegex(
DeprecationWarning,
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
r"use site configuration instead\. Future versions of Python may "
r"not enable this finder by default\."
):
spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
self.assertIsNone(spec)

def test_module_found(self):
with setup_module(self.machinery, self.test_module):
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
with self.assertWarnsRegex(
DeprecationWarning,
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
r"use site configuration instead\. Future versions of Python may "
r"not enable this finder by default\."
):
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
self.assertIsNotNone(spec)

def test_module_not_found(self):
with setup_module(self.machinery, self.test_module, path="."):
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
with self.assertWarnsRegex(
DeprecationWarning,
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
r"use site configuration instead\. Future versions of Python may "
r"not enable this finder by default\."
):
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
self.assertIsNone(spec)

def test_raises_deprecation_warning(self):
# WindowsRegistryFinder is not meant to be instantiated, so the
# deprecation warning is raised in the 'find_spec' method instead.
with self.assertWarns(DeprecationWarning):
with self.assertWarnsRegex(
DeprecationWarning,
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
r"use site configuration instead\. Future versions of Python may "
r"not enable this finder by default\."
):
self.machinery.WindowsRegistryFinder.find_spec('spam')

(Frozen_WindowsRegistryFinderTests,
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
30 changes: 22 additions & 8 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest
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,
warnings_helper,
)
import _thread as thread
import array
Expand Down Expand Up @@ -198,6 +199,16 @@ def socket_setdefaulttimeout(timeout):
socket.setdefaulttimeout(old_timeout)


@contextlib.contextmanager
def catch_malformed_data_warning(quiet=True):
# This warning happens on macos and win, but does not always happen on linux.
with warnings_helper.check_warnings(
("received malformed or improperly-truncated ancillary data", RuntimeWarning),
quiet=quiet,
):
yield


HAVE_SOCKET_CAN = _have_socket_can()

HAVE_SOCKET_CAN_ISOTP = _have_socket_can_isotp()
Expand Down Expand Up @@ -3946,8 +3957,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 catch_malformed_data_warning():
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 @@ -4298,8 +4310,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 catch_malformed_data_warning():
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 @@ -4402,9 +4415,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 catch_malformed_data_warning():
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