Skip to content

Commit 96b344c

Browse files
tiranbrettcannon
andauthored
bpo-40280: Address more test failures on Emscripten (GH-31050)
Co-authored-by: Brett Cannon <[email protected]>
1 parent 9d4161a commit 96b344c

27 files changed

+228
-50
lines changed

Lib/test/support/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,8 @@ def reap_children():
12781278
# Need os.waitpid(-1, os.WNOHANG): Windows is not supported
12791279
if not (hasattr(os, 'waitpid') and hasattr(os, 'WNOHANG')):
12801280
return
1281+
elif not has_subprocess_support:
1282+
return
12811283

12821284
# Reap all our dead child processes so we don't leave zombies around.
12831285
# These hog resources and might be causing some of the buildbots to die.

Lib/test/support/os_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def __fspath__(self):
502502
def fd_count():
503503
"""Count the number of open file descriptors.
504504
"""
505-
if sys.platform.startswith(('linux', 'freebsd')):
505+
if sys.platform.startswith(('linux', 'freebsd', 'emscripten')):
506506
try:
507507
names = os.listdir("/proc/self/fd")
508508
# Subtract one because listdir() internally opens a file

Lib/test/test_builtin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ def test_compile_top_level_await_no_coro(self):
393393
msg=f"source={source} mode={mode}")
394394

395395

396+
@unittest.skipIf(support.is_emscripten, "socket.accept is broken")
396397
def test_compile_top_level_await(self):
397398
"""Test whether code some top level await can be compiled.
398399
@@ -1213,6 +1214,7 @@ def test_open_default_encoding(self):
12131214
os.environ.clear()
12141215
os.environ.update(old_environ)
12151216

1217+
@support.requires_subprocess()
12161218
def test_open_non_inheritable(self):
12171219
fileobj = open(__file__, encoding="utf-8")
12181220
with fileobj:

Lib/test/test_capi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ def check_fatal_error(self, code, expected, not_expected=()):
611611
self.assertNotIn(name, modules)
612612
self.assertEqual(len(modules), total)
613613

614+
@support.requires_subprocess()
614615
def test_fatal_error(self):
615616
# By default, stdlib extension modules are ignored,
616617
# but not test modules.
@@ -880,6 +881,7 @@ class Test_testinternalcapi(unittest.TestCase):
880881
if name.startswith('test_'))
881882

882883

884+
@support.requires_subprocess()
883885
class PyMemDebugTests(unittest.TestCase):
884886
PYTHONMALLOC = 'debug'
885887
# '0x04c06e0' or '04C06E0'

Lib/test/test_faulthandler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
except ImportError:
2020
_testcapi = None
2121

22+
if not support.has_subprocess_support:
23+
raise unittest.SkipTest("test module requires subprocess")
24+
2225
TIMEOUT = 0.5
2326
MS_WINDOWS = (os.name == 'nt')
2427

Lib/test/test_fileio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from weakref import proxy
1010
from functools import wraps
1111

12-
from test.support import cpython_only, swap_attr, gc_collect
12+
from test.support import cpython_only, swap_attr, gc_collect, is_emscripten
1313
from test.support.os_helper import (TESTFN, TESTFN_UNICODE, make_bad_fd)
1414
from test.support.warnings_helper import check_warnings
1515
from collections import UserList
@@ -373,7 +373,7 @@ def testAbles(self):
373373
self.assertEqual(f.isatty(), False)
374374
f.close()
375375

376-
if sys.platform != "win32":
376+
if sys.platform != "win32" and not is_emscripten:
377377
try:
378378
f = self.FileIO("/dev/tty", "a")
379379
except OSError:

Lib/test/test_genericalias.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@
2424
from fileinput import FileInput
2525
from itertools import chain
2626
from http.cookies import Morsel
27-
from multiprocessing.managers import ValueProxy
28-
from multiprocessing.pool import ApplyResult
27+
try:
28+
from multiprocessing.managers import ValueProxy
29+
from multiprocessing.pool import ApplyResult
30+
from multiprocessing.queues import SimpleQueue as MPSimpleQueue
31+
except ImportError:
32+
# _multiprocessing module is optional
33+
ValueProxy = None
34+
ApplyResult = None
35+
MPSimpleQueue = None
2936
try:
3037
from multiprocessing.shared_memory import ShareableList
3138
except ImportError:
3239
# multiprocessing.shared_memory is not available on e.g. Android
3340
ShareableList = None
34-
from multiprocessing.queues import SimpleQueue as MPSimpleQueue
3541
from os import DirEntry
3642
from re import Pattern, Match
3743
from types import GenericAlias, MappingProxyType, AsyncGeneratorType
@@ -79,13 +85,14 @@ class BaseTest(unittest.TestCase):
7985
Queue, SimpleQueue,
8086
_AssertRaisesContext,
8187
SplitResult, ParseResult,
82-
ValueProxy, ApplyResult,
8388
WeakSet, ReferenceType, ref,
84-
ShareableList, MPSimpleQueue,
89+
ShareableList,
8590
Future, _WorkItem,
8691
Morsel]
8792
if ctypes is not None:
8893
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
94+
if ValueProxy is not None:
95+
generic_types.extend((ValueProxy, ApplyResult, MPSimpleQueue))
8996

9097
def test_subscriptable(self):
9198
for t in self.generic_types:

Lib/test/test_getpass.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def test_username_priorities_of_env_values(self, environ):
2828
getpass.getuser()
2929
except ImportError: # in case there's no pwd module
3030
pass
31+
except KeyError:
32+
# current user has no pwd entry
33+
pass
3134
self.assertEqual(
3235
environ.get.call_args_list,
3336
[mock.call(x) for x in ('LOGNAME', 'USER', 'LNAME', 'USERNAME')])

Lib/test/test_inspect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ def test_nested_class_definition_inside_function(self):
788788
self.assertSourceEqual(mod2.cls213, 218, 222)
789789
self.assertSourceEqual(mod2.cls213().func219(), 220, 221)
790790

791+
@unittest.skipIf(support.is_emscripten, "socket.accept is broken")
791792
def test_nested_class_definition_inside_async_function(self):
792793
import asyncio
793794
self.addCleanup(asyncio.set_event_loop_policy, None)

Lib/test/test_interpreters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import unittest
66
import time
77

8-
import _xxsubinterpreters as _interpreters
8+
from test.support import import_helper
9+
_interpreters = import_helper.import_module('_xxsubinterpreters')
910
from test.support import interpreters
1011

1112

0 commit comments

Comments
 (0)