Skip to content

Commit d20fdb2

Browse files
committed
bpo-40280: Skip subprocess tests on wasm32-emscripten / wasi
1 parent d75a51b commit d20fdb2

Some content is hidden

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

42 files changed

+139
-23
lines changed

Lib/distutils/tests/test_build_clib.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import sys
55
import sysconfig
66

7-
from test.support import run_unittest, missing_compiler_executable
7+
from test.support import (
8+
run_unittest, missing_compiler_executable, requires_subprocess
9+
)
810

911
from distutils.command.build_clib import build_clib
1012
from distutils.errors import DistutilsSetupError
@@ -112,6 +114,7 @@ def test_finalize_options(self):
112114
self.assertRaises(DistutilsSetupError, cmd.finalize_options)
113115

114116
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
117+
@requires_subprocess()
115118
def test_run(self):
116119
pkg_dir, dist = self.create_dist()
117120
cmd = build_clib(dist)

Lib/distutils/tests/test_build_ext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def tearDown(self):
5656
def build_ext(self, *args, **kwargs):
5757
return build_ext(*args, **kwargs)
5858

59+
@support.requires_subprocess()
5960
def test_build_ext(self):
6061
cmd = support.missing_compiler_executable()
6162
if cmd is not None:
@@ -332,6 +333,7 @@ def test_compiler_option(self):
332333
cmd.run()
333334
self.assertEqual(cmd.compiler, 'unix')
334335

336+
@support.requires_subprocess()
335337
def test_get_outputs(self):
336338
cmd = support.missing_compiler_executable()
337339
if cmd is not None:

Lib/distutils/tests/test_build_py.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from distutils.errors import DistutilsFileError
1010

1111
from distutils.tests import support
12-
from test.support import run_unittest
12+
from test.support import run_unittest, requires_subprocess
1313

1414

1515
class BuildPyTestCase(support.TempdirManager,
@@ -89,6 +89,7 @@ def test_empty_package_dir(self):
8989
self.fail("failed package_data test when package_dir is ''")
9090

9191
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
92+
@requires_subprocess()
9293
def test_byte_compile(self):
9394
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
9495
os.chdir(project_dir)
@@ -106,6 +107,7 @@ def test_byte_compile(self):
106107
['boiledeggs.%s.pyc' % sys.implementation.cache_tag])
107108

108109
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
110+
@requires_subprocess()
109111
def test_byte_compile_optimized(self):
110112
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
111113
os.chdir(project_dir)

Lib/distutils/tests/test_config_cmd.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import os
44
import sys
55
import sysconfig
6-
from test.support import run_unittest, missing_compiler_executable
6+
from test.support import (
7+
run_unittest, missing_compiler_executable, requires_subprocess
8+
)
79

810
from distutils.command.config import dump_file, config
911
from distutils.tests import support
@@ -42,6 +44,7 @@ def test_dump_file(self):
4244
self.assertEqual(len(self._logs), numlines+1)
4345

4446
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
47+
@requires_subprocess()
4548
def test_search_cpp(self):
4649
cmd = missing_compiler_executable(['preprocessor'])
4750
if cmd is not None:

Lib/distutils/tests/test_install.py

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

8-
from test.support import captured_stdout, run_unittest
8+
from test.support import captured_stdout, run_unittest, requires_subprocess
99

1010
from distutils import sysconfig
1111
from distutils.command.install import install, HAS_USER_SITE
@@ -208,6 +208,7 @@ def test_record(self):
208208
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
209209
self.assertEqual(found, expected)
210210

211+
@requires_subprocess()
211212
def test_record_extensions(self):
212213
cmd = test_support.missing_compiler_executable()
213214
if cmd is not None:

Lib/distutils/tests/test_install_lib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from distutils.extension import Extension
99
from distutils.tests import support
1010
from distutils.errors import DistutilsOptionError
11-
from test.support import run_unittest
11+
from test.support import run_unittest, requires_subprocess
1212

1313

1414
class InstallLibTestCase(support.TempdirManager,
@@ -35,6 +35,7 @@ def test_finalize_options(self):
3535
self.assertEqual(cmd.optimize, 2)
3636

3737
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
38+
@requires_subprocess()
3839
def test_byte_compile(self):
3940
project_dir, dist = self.create_dist()
4041
os.chdir(project_dir)
@@ -90,6 +91,7 @@ def test_get_inputs(self):
9091
inputs = cmd.get_inputs()
9192
self.assertEqual(len(inputs), 2, inputs)
9293

94+
@requires_subprocess()
9395
def test_dont_write_bytecode(self):
9496
# makes sure byte_compile is not used
9597
dist = self.create_dist()[1]

Lib/distutils/tests/test_spawn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import stat
44
import sys
55
import unittest.mock
6-
from test.support import run_unittest, unix_shell
6+
from test.support import run_unittest, unix_shell, requires_subprocess
77
from test.support import os_helper
88

99
from distutils.spawn import find_executable
1010
from distutils.spawn import spawn
1111
from distutils.errors import DistutilsExecError
1212
from distutils.tests import support
1313

14+
15+
@requires_subprocess()
1416
class SpawnTestCase(support.TempdirManager,
1517
support.LoggingSilencer,
1618
unittest.TestCase):

Lib/distutils/tests/test_sysconfig.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from distutils import sysconfig
1111
from distutils.ccompiler import get_default_compiler
1212
from distutils.tests import support
13-
from test.support import run_unittest, swap_item
13+
from test.support import run_unittest, swap_item, requires_subprocess
1414
from test.support.os_helper import TESTFN
1515
from test.support.warnings_helper import check_warnings
1616

@@ -247,6 +247,7 @@ def test_SO_in_vars(self):
247247
self.assertIsNotNone(vars['SO'])
248248
self.assertEqual(vars['SO'], vars['EXT_SUFFIX'])
249249

250+
@requires_subprocess()
250251
def test_customize_compiler_before_get_config_vars(self):
251252
# Issue #21923: test that a Distribution compiler
252253
# instance can be called without an explicit call to

Lib/lib2to3/tests/test_parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def test_load_grammar_from_pickle(self):
6161
shutil.rmtree(tmpdir)
6262

6363
@unittest.skipIf(sys.executable is None, 'sys.executable required')
64+
@unittest.skipIf(
65+
sys.platform == 'emscripten', 'requires working subprocess'
66+
)
6467
def test_load_grammar_from_subprocess(self):
6568
tmpdir = tempfile.mkdtemp()
6669
tmpsubdir = os.path.join(tmpdir, 'subdir')

Lib/test/support/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@
4040
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
4141
"requires_IEEE_754", "requires_zlib",
4242
"has_fork_support", "requires_fork",
43+
"has_subprocess_support", "requires_subprocess",
4344
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
4445
"check__all__", "skip_if_buggy_ucrt_strfptime",
4546
"check_disallow_instantiation",
4647
# sys
47-
"is_jython", "is_android", "is_emscripten",
48+
"is_jython", "is_android", "is_emscripten", "is_wasi",
4849
"check_impl_detail", "unix_shell", "setswitchinterval",
4950
# network
5051
"open_urlresource",
@@ -467,15 +468,23 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
467468
else:
468469
unix_shell = None
469470

470-
# wasm32-emscripten is POSIX-like but does not provide a
471-
# working fork() or subprocess API.
471+
# wasm32-emscripten and -wasi are POSIX-like but do not
472+
# have subprocess or fork support.
472473
is_emscripten = sys.platform == "emscripten"
474+
is_wasi = sys.platform == "wasi"
473475

474-
has_fork_support = hasattr(os, "fork") and not is_emscripten
476+
has_fork_support = hasattr(os, "fork") and not is_emscripten and not is_wasi
475477

476478
def requires_fork():
477479
return unittest.skipUnless(has_fork_support, "requires working os.fork()")
478480

481+
has_subprocess_support = not is_emscripten and not is_wasi
482+
483+
def requires_subprocess():
484+
"""Used for subprocess, os.spawn calls"""
485+
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
486+
487+
479488
# Define the URL of a dedicated HTTP server for the network tests.
480489
# The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
481490
TEST_HTTP_URL = "http://www.pythontest.net"

Lib/test/support/script_helper.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def interpreter_requires_environment():
4242
if 'PYTHONHOME' in os.environ:
4343
__cached_interp_requires_environment = True
4444
return True
45+
# cannot run subprocess, assume we don't need it
46+
if not support.has_subprocess_support:
47+
__cached_interp_requires_environment = False
48+
return False
4549

4650
# Try running an interpreter with -E to see if it works or not.
4751
try:
@@ -87,6 +91,7 @@ def fail(self, cmd_line):
8791

8892

8993
# Executing the interpreter in a subprocess
94+
@support.requires_subprocess()
9095
def run_python_until_end(*args, **env_vars):
9196
env_required = interpreter_requires_environment()
9297
cwd = env_vars.pop('__cwd', None)
@@ -139,6 +144,7 @@ def run_python_until_end(*args, **env_vars):
139144
return _PythonRunResult(rc, out, err), cmd_line
140145

141146

147+
@support.requires_subprocess()
142148
def _assert_python(expected_success, /, *args, **env_vars):
143149
res, cmd_line = run_python_until_end(*args, **env_vars)
144150
if (res.rc and expected_success) or (not res.rc and not expected_success):
@@ -171,6 +177,7 @@ def assert_python_failure(*args, **env_vars):
171177
return _assert_python(False, *args, **env_vars)
172178

173179

180+
@support.requires_subprocess()
174181
def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
175182
"""Run a Python subprocess with the given arguments.
176183
@@ -273,6 +280,7 @@ def make_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename,
273280
return zip_name, os.path.join(zip_name, script_name_in_zip)
274281

275282

283+
@support.requires_subprocess()
276284
def run_test_script(script):
277285
# use -u to try to get the full output if the test hangs or crash
278286
if support.verbose:

Lib/test/test_audit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717

1818
class AuditTest(unittest.TestCase):
19+
20+
@support.requires_subprocess()
1921
def do_test(self, *args):
2022
with subprocess.Popen(
2123
[sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args],
@@ -29,6 +31,7 @@ def do_test(self, *args):
2931
if p.returncode:
3032
self.fail("".join(p.stderr))
3133

34+
@support.requires_subprocess()
3235
def run_python(self, *args):
3336
events = []
3437
with subprocess.Popen(

Lib/test/test_capi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def test_instancemethod(self):
6666
self.assertEqual(testfunction.attribute, "test")
6767
self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test")
6868

69+
@support.requires_subprocess()
6970
def test_no_FatalError_infinite_loop(self):
7071
with support.SuppressCrashReport():
7172
p = subprocess.Popen([sys.executable, "-c",

Lib/test/test_cmd_line.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
interpreter_requires_environment
1616
)
1717

18+
if not support.has_subprocess_support:
19+
raise unittest.SkipTest("test module requires subprocess")
1820

1921
# Debug build?
2022
Py_DEBUG = hasattr(sys, "gettotalrefcount")

Lib/test/test_embed.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import tempfile
1818
import textwrap
1919

20+
if not support.has_subprocess_support:
21+
raise unittest.SkipTest("test module requires subprocess")
2022

2123
MS_WINDOWS = (os.name == 'nt')
2224
MACOS = (sys.platform == 'darwin')

Lib/test/test_faulthandler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ def test_is_enabled(self):
412412
finally:
413413
sys.stderr = orig_stderr
414414

415+
@support.requires_subprocess()
415416
def test_disabled_by_default(self):
416417
# By default, the module should be disabled
417418
code = "import faulthandler; print(faulthandler.is_enabled())"
@@ -420,6 +421,7 @@ def test_disabled_by_default(self):
420421
output = subprocess.check_output(args)
421422
self.assertEqual(output.rstrip(), b"False")
422423

424+
@support.requires_subprocess()
423425
def test_sys_xoptions(self):
424426
# Test python -X faulthandler
425427
code = "import faulthandler; print(faulthandler.is_enabled())"
@@ -432,6 +434,7 @@ def test_sys_xoptions(self):
432434
output = subprocess.check_output(args, env=env)
433435
self.assertEqual(output.rstrip(), b"True")
434436

437+
@support.requires_subprocess()
435438
def test_env_var(self):
436439
# empty env var
437440
code = "import faulthandler; print(faulthandler.is_enabled())"

Lib/test/test_file_eintr.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
import sys
1616
import time
1717
import unittest
18+
from test import support
19+
20+
if not support.has_subprocess_support:
21+
raise unittest.SkipTest("test module requires subprocess")
1822

1923
# Test import all of the things we're about to try testing up front.
2024
import _io
2125
import _pyio
2226

23-
2427
@unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.')
2528
class TestFileIOSignalInterrupt:
2629
def setUp(self):

Lib/test/test_gc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
import unittest.mock
33
from test.support import (verbose, refcount_test,
4-
cpython_only)
4+
cpython_only, requires_subprocess)
55
from test.support.import_helper import import_module
66
from test.support.os_helper import temp_dir, TESTFN, unlink
77
from test.support.script_helper import assert_python_ok, make_script
@@ -661,6 +661,7 @@ def do_work():
661661
gc.collect() # this blows up (bad C pointer) when it fails
662662

663663
@cpython_only
664+
@requires_subprocess()
664665
def test_garbage_at_shutdown(self):
665666
import subprocess
666667
code = """if 1:

Lib/test/test_gzip.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from subprocess import PIPE, Popen
1313
from test.support import import_helper
1414
from test.support import os_helper
15-
from test.support import _4G, bigmemtest
15+
from test.support import _4G, bigmemtest, requires_subprocess
1616
from test.support.script_helper import assert_python_ok, assert_python_failure
1717

1818
gzip = import_helper.import_module('gzip')
@@ -760,6 +760,7 @@ def wrapper(*args, **kwargs):
760760
class TestCommandLine(unittest.TestCase):
761761
data = b'This is a simple test with gzip'
762762

763+
@requires_subprocess()
763764
def test_decompress_stdin_stdout(self):
764765
with io.BytesIO() as bytes_io:
765766
with gzip.GzipFile(fileobj=bytes_io, mode='wb') as gzip_file:
@@ -795,6 +796,7 @@ def test_decompress_infile_outfile_error(self):
795796
self.assertEqual(rc, 1)
796797
self.assertEqual(out, b'')
797798

799+
@requires_subprocess()
798800
@create_and_remove_directory(TEMPDIR)
799801
def test_compress_stdin_outfile(self):
800802
args = sys.executable, '-m', 'gzip'

0 commit comments

Comments
 (0)