Skip to content

Commit 760ec89

Browse files
authored
gh-90473: WASI: skip gethostname tests (GH-93092)
- WASI's ``gethostname()`` is a stub that always fails with OSError ``ENOTSUP`` - skip mailcap ``test`` if subprocess is not available - WASI process_time clock does not work.
1 parent 88f0d0c commit 760ec89

9 files changed

+30
-0
lines changed

Lib/test/support/socket_helper.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
HOSTv4 = "127.0.0.1"
1212
HOSTv6 = "::1"
1313

14+
# WASI SDK 15.0 does not provide gethostname, stub raises OSError ENOTSUP.
15+
has_gethostname = not support.is_wasi
16+
1417

1518
def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM):
1619
"""Returns an unused port that should be suitable for binding. This is

Lib/test/test_mailbox.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
import tempfile
1111
from test import support
1212
from test.support import os_helper
13+
from test.support import socket_helper
1314
import unittest
1415
import textwrap
1516
import mailbox
1617
import glob
1718

1819

20+
if not socket_helper.has_gethostname:
21+
raise unittest.SkipTest("test requires gethostname()")
22+
23+
1924
class TestBase:
2025

2126
all_mailbox_types = (mailbox.Message, mailbox.MaildirMessage,

Lib/test/test_mailcap.py

+4
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ def test_findmatch(self):
221221

222222
@unittest.skipUnless(os.name == "posix", "Requires 'test' command on system")
223223
@unittest.skipIf(sys.platform == "vxworks", "'test' command is not supported on VxWorks")
224+
@unittest.skipUnless(
225+
test.support.has_subprocess_support,
226+
"'test' command needs process support."
227+
)
224228
def test_test(self):
225229
# findmatch() will automatically check any "test" conditions and skip
226230
# the entry if the check fails.

Lib/test/test_smtpd.py

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
smtpd = warnings_helper.import_deprecated('smtpd')
1111
asyncore = warnings_helper.import_deprecated('asyncore')
1212

13+
if not socket_helper.has_gethostname:
14+
raise unittest.SkipTest("test requires gethostname()")
15+
1316

1417
class DummyServer(smtpd.SMTPServer):
1518
def __init__(self, *args, **kwargs):

Lib/test/test_support.py

+1
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ def id(self):
664664
self.assertTrue(support.match_test(test_chdir))
665665

666666
@unittest.skipIf(support.is_emscripten, "Unstable in Emscripten")
667+
@unittest.skipIf(support.is_wasi, "Unavailable on WASI")
667668
def test_fd_count(self):
668669
# We cannot test the absolute value of fd_count(): on old Linux
669670
# kernel or glibc versions, os.urandom() keeps a FD open on

Lib/test/test_time.py

+3
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ def test_monotonic(self):
489489
def test_perf_counter(self):
490490
time.perf_counter()
491491

492+
@unittest.skipIf(
493+
support.is_wasi, "process_time not available on WASI"
494+
)
492495
def test_process_time(self):
493496
# process_time() should not include time spend during a sleep
494497
start = time.process_time()

Lib/test/test_urllib.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from unittest.mock import patch
1111
from test import support
1212
from test.support import os_helper
13+
from test.support import socket_helper
1314
from test.support import warnings_helper
1415
import os
1516
try:
@@ -24,6 +25,10 @@
2425
import collections
2526

2627

28+
if not socket_helper.has_gethostname:
29+
raise unittest.SkipTest("test requires gethostname()")
30+
31+
2732
def hexescape(char):
2833
"""Escape char as RFC 2396 specifies"""
2934
hex_repr = hex(ord(char))[2:].upper()

Lib/test/test_urllib_response.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import tempfile
55
import urllib.response
66
import unittest
7+
from test import support
8+
9+
if support.is_wasi:
10+
raise unittest.SkipTest("Cannot create socket on WASI")
11+
712

813
class TestResponse(unittest.TestCase):
914

Tools/wasm/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ are:
239239
yet. A future version of WASI may provide a limited ``set_permissions`` API.
240240
- File locking (``fcntl``) is not available.
241241
- ``os.pipe()``, ``os.mkfifo()``, and ``os.mknod()`` are not supported.
242+
- ``process_time`` clock does not work.
242243

243244

244245
# Detect WebAssembly builds

0 commit comments

Comments
 (0)