Skip to content

Commit deeaac4

Browse files
authored
bpo-40280: Skip socket, fork, subprocess tests on Emscripten (GH-31986)
- Add requires_fork and requires_subprocess to more tests - Skip extension import tests if dlopen is not available - Don't assume that _testcapi is a shared extension - Skip a lot of socket tests that don't work on Emscripten - Skip mmap tests, mmap emulation is incomplete - venv does not work yet - Cannot get libc from executable The "entire" test suite is now passing on Emscripten with EMSDK from git head (91 suites are skipped).
1 parent a25a985 commit deeaac4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+238
-23
lines changed

Lib/test/lock_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from test.support import threading_helper
1616

1717

18-
requires_fork = unittest.skipUnless(hasattr(os, 'fork'),
18+
requires_fork = unittest.skipUnless(support.has_fork_support,
1919
"platform doesn't support fork "
2020
"(no _at_fork_reinit method)")
2121

Lib/test/pythoninfo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import sys
88
import traceback
9+
import unittest
910
import warnings
1011

1112

@@ -615,7 +616,7 @@ def collect_resource(info_add):
615616
def collect_test_socket(info_add):
616617
try:
617618
from test import test_socket
618-
except ImportError:
619+
except (ImportError, unittest.SkipTest):
619620
return
620621

621622
# all check attributes like HAVE_SOCKET_CAN

Lib/test/support/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"requires_IEEE_754", "requires_zlib",
4343
"has_fork_support", "requires_fork",
4444
"has_subprocess_support", "requires_subprocess",
45+
"has_socket_support", "requires_working_socket",
4546
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
4647
"check__all__", "skip_if_buggy_ucrt_strfptime",
4748
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
@@ -520,6 +521,21 @@ def requires_subprocess():
520521
"""Used for subprocess, os.spawn calls, fd inheritance"""
521522
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
522523

524+
# Emscripten's socket emulation has limitation. WASI doesn't have sockets yet.
525+
has_socket_support = not is_emscripten and not is_wasi
526+
527+
def requires_working_socket(*, module=False):
528+
"""Skip tests or modules that require working sockets
529+
530+
Can be used as a function/class decorator or to skip an entire module.
531+
"""
532+
msg = "requires socket support"
533+
if module:
534+
if not has_socket_support:
535+
raise unittest.SkipTest(msg)
536+
else:
537+
return unittest.skipUnless(has_socket_support, msg)
538+
523539
# Does strftime() support glibc extension like '%4Y'?
524540
has_strftime_extensions = False
525541
if sys.platform != "win32":

Lib/test/test_asyncgen.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import contextlib
55

66
from test.support.import_helper import import_module
7-
from test.support import gc_collect
7+
from test.support import gc_collect, requires_working_socket
88
asyncio = import_module("asyncio")
99

1010

11+
requires_working_socket(module=True)
12+
1113
_no_default = object()
1214

1315

Lib/test/test_asynchat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import asynchat
1919
import asyncore
2020

21+
support.requires_working_socket(module=True)
22+
2123
HOST = socket_helper.HOST
2224
SERVER_QUIT = b'QUIT\n'
2325

Lib/test/test_asyncio/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
2+
from test import support
23
from test.support import load_package_tests
34
from test.support import import_helper
45

6+
support.requires_working_socket(module=True)
57

68
# Skip tests if we don't have concurrent.futures.
79
import_helper.import_module('concurrent.futures')

Lib/test/test_asyncore.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
if support.PGO:
1919
raise unittest.SkipTest("test is not helpful for PGO")
2020

21+
support.requires_working_socket(module=True)
22+
2123
import warnings
2224
with warnings.catch_warnings():
2325
warnings.simplefilter('ignore', DeprecationWarning)

Lib/test/test_contextlib_async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from test.test_contextlib import TestBaseExitStack
1010

11+
support.requires_working_socket(module=True)
1112

1213
def _async_test(func):
1314
"""Decorator to turn an async function into a test case."""

Lib/test/test_doctest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
import types
1919
import contextlib
2020

21+
22+
if not support.has_subprocess_support:
23+
raise unittest.SkipTest("test_CLI requires subprocess support.")
24+
25+
2126
# NOTE: There are some additional tests relating to interaction with
2227
# zipimport in the test_zipimport_support test module.
2328

@@ -455,7 +460,7 @@ def basics(): r"""
455460
>>> tests = finder.find(sample_func)
456461
457462
>>> print(tests) # doctest: +ELLIPSIS
458-
[<DocTest sample_func from test_doctest.py:28 (1 example)>]
463+
[<DocTest sample_func from test_doctest.py:33 (1 example)>]
459464
460465
The exact name depends on how test_doctest was invoked, so allow for
461466
leading path components.

Lib/test/test_docxmlrpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import sys
55
import threading
66
import unittest
7+
from test import support
8+
9+
support.requires_working_socket(module=True)
710

811
def make_request_and_skipIf(condition, reason):
912
# If we skip the test, we have to make a request because

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy