bpo-40280: Skip subprocess-based tests on wasm32-emscripten (GH-30615)

This commit is contained in:
Christian Heimes 2022-01-25 09:09:06 +02:00 committed by GitHub
parent e1abffca45
commit 8464fbc42e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 139 additions and 23 deletions

View file

@ -4,7 +4,9 @@ import os
import sys import sys
import sysconfig import sysconfig
from test.support import run_unittest, missing_compiler_executable from test.support import (
run_unittest, missing_compiler_executable, requires_subprocess
)
from distutils.command.build_clib import build_clib from distutils.command.build_clib import build_clib
from distutils.errors import DistutilsSetupError from distutils.errors import DistutilsSetupError
@ -112,6 +114,7 @@ class BuildCLibTestCase(support.TempdirManager,
self.assertRaises(DistutilsSetupError, cmd.finalize_options) self.assertRaises(DistutilsSetupError, cmd.finalize_options)
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows") @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
@requires_subprocess()
def test_run(self): def test_run(self):
pkg_dir, dist = self.create_dist() pkg_dir, dist = self.create_dist()
cmd = build_clib(dist) cmd = build_clib(dist)

View file

@ -56,6 +56,7 @@ class BuildExtTestCase(TempdirManager,
def build_ext(self, *args, **kwargs): def build_ext(self, *args, **kwargs):
return build_ext(*args, **kwargs) return build_ext(*args, **kwargs)
@support.requires_subprocess()
def test_build_ext(self): def test_build_ext(self):
cmd = support.missing_compiler_executable() cmd = support.missing_compiler_executable()
if cmd is not None: if cmd is not None:
@ -332,6 +333,7 @@ class BuildExtTestCase(TempdirManager,
cmd.run() cmd.run()
self.assertEqual(cmd.compiler, 'unix') self.assertEqual(cmd.compiler, 'unix')
@support.requires_subprocess()
def test_get_outputs(self): def test_get_outputs(self):
cmd = support.missing_compiler_executable() cmd = support.missing_compiler_executable()
if cmd is not None: if cmd is not None:

View file

@ -9,7 +9,7 @@ from distutils.core import Distribution
from distutils.errors import DistutilsFileError from distutils.errors import DistutilsFileError
from distutils.tests import support from distutils.tests import support
from test.support import run_unittest from test.support import run_unittest, requires_subprocess
class BuildPyTestCase(support.TempdirManager, class BuildPyTestCase(support.TempdirManager,
@ -89,6 +89,7 @@ class BuildPyTestCase(support.TempdirManager,
self.fail("failed package_data test when package_dir is ''") self.fail("failed package_data test when package_dir is ''")
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled') @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
@requires_subprocess()
def test_byte_compile(self): def test_byte_compile(self):
project_dir, dist = self.create_dist(py_modules=['boiledeggs']) project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
os.chdir(project_dir) os.chdir(project_dir)
@ -106,6 +107,7 @@ class BuildPyTestCase(support.TempdirManager,
['boiledeggs.%s.pyc' % sys.implementation.cache_tag]) ['boiledeggs.%s.pyc' % sys.implementation.cache_tag])
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled') @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
@requires_subprocess()
def test_byte_compile_optimized(self): def test_byte_compile_optimized(self):
project_dir, dist = self.create_dist(py_modules=['boiledeggs']) project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
os.chdir(project_dir) os.chdir(project_dir)

View file

@ -3,7 +3,9 @@ import unittest
import os import os
import sys import sys
import sysconfig import sysconfig
from test.support import run_unittest, missing_compiler_executable from test.support import (
run_unittest, missing_compiler_executable, requires_subprocess
)
from distutils.command.config import dump_file, config from distutils.command.config import dump_file, config
from distutils.tests import support from distutils.tests import support
@ -42,6 +44,7 @@ class ConfigTestCase(support.LoggingSilencer,
self.assertEqual(len(self._logs), numlines+1) self.assertEqual(len(self._logs), numlines+1)
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows") @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
@requires_subprocess()
def test_search_cpp(self): def test_search_cpp(self):
cmd = missing_compiler_executable(['preprocessor']) cmd = missing_compiler_executable(['preprocessor'])
if cmd is not None: if cmd is not None:

View file

@ -5,7 +5,7 @@ import sys
import unittest import unittest
import site import site
from test.support import captured_stdout, run_unittest from test.support import captured_stdout, run_unittest, requires_subprocess
from distutils import sysconfig from distutils import sysconfig
from distutils.command.install import install, HAS_USER_SITE from distutils.command.install import install, HAS_USER_SITE
@ -208,6 +208,7 @@ class InstallTestCase(support.TempdirManager,
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]] 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
self.assertEqual(found, expected) self.assertEqual(found, expected)
@requires_subprocess()
def test_record_extensions(self): def test_record_extensions(self):
cmd = test_support.missing_compiler_executable() cmd = test_support.missing_compiler_executable()
if cmd is not None: if cmd is not None:

View file

@ -8,7 +8,7 @@ from distutils.command.install_lib import install_lib
from distutils.extension import Extension from distutils.extension import Extension
from distutils.tests import support from distutils.tests import support
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
from test.support import run_unittest from test.support import run_unittest, requires_subprocess
class InstallLibTestCase(support.TempdirManager, class InstallLibTestCase(support.TempdirManager,
@ -35,6 +35,7 @@ class InstallLibTestCase(support.TempdirManager,
self.assertEqual(cmd.optimize, 2) self.assertEqual(cmd.optimize, 2)
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled') @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
@requires_subprocess()
def test_byte_compile(self): def test_byte_compile(self):
project_dir, dist = self.create_dist() project_dir, dist = self.create_dist()
os.chdir(project_dir) os.chdir(project_dir)
@ -90,6 +91,7 @@ class InstallLibTestCase(support.TempdirManager,
inputs = cmd.get_inputs() inputs = cmd.get_inputs()
self.assertEqual(len(inputs), 2, inputs) self.assertEqual(len(inputs), 2, inputs)
@requires_subprocess()
def test_dont_write_bytecode(self): def test_dont_write_bytecode(self):
# makes sure byte_compile is not used # makes sure byte_compile is not used
dist = self.create_dist()[1] dist = self.create_dist()[1]

View file

@ -3,7 +3,7 @@ import os
import stat import stat
import sys import sys
import unittest.mock import unittest.mock
from test.support import run_unittest, unix_shell from test.support import run_unittest, unix_shell, requires_subprocess
from test.support import os_helper from test.support import os_helper
from distutils.spawn import find_executable from distutils.spawn import find_executable
@ -11,6 +11,8 @@ from distutils.spawn import spawn
from distutils.errors import DistutilsExecError from distutils.errors import DistutilsExecError
from distutils.tests import support from distutils.tests import support
@requires_subprocess()
class SpawnTestCase(support.TempdirManager, class SpawnTestCase(support.TempdirManager,
support.LoggingSilencer, support.LoggingSilencer,
unittest.TestCase): unittest.TestCase):

View file

@ -10,7 +10,7 @@ import unittest
from distutils import sysconfig from distutils import sysconfig
from distutils.ccompiler import get_default_compiler from distutils.ccompiler import get_default_compiler
from distutils.tests import support from distutils.tests import support
from test.support import run_unittest, swap_item from test.support import run_unittest, swap_item, requires_subprocess
from test.support.os_helper import TESTFN from test.support.os_helper import TESTFN
from test.support.warnings_helper import check_warnings from test.support.warnings_helper import check_warnings
@ -247,6 +247,7 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
self.assertIsNotNone(vars['SO']) self.assertIsNotNone(vars['SO'])
self.assertEqual(vars['SO'], vars['EXT_SUFFIX']) self.assertEqual(vars['SO'], vars['EXT_SUFFIX'])
@requires_subprocess()
def test_customize_compiler_before_get_config_vars(self): def test_customize_compiler_before_get_config_vars(self):
# Issue #21923: test that a Distribution compiler # Issue #21923: test that a Distribution compiler
# instance can be called without an explicit call to # instance can be called without an explicit call to

View file

@ -61,6 +61,9 @@ class TestPgen2Caching(support.TestCase):
shutil.rmtree(tmpdir) shutil.rmtree(tmpdir)
@unittest.skipIf(sys.executable is None, 'sys.executable required') @unittest.skipIf(sys.executable is None, 'sys.executable required')
@unittest.skipIf(
sys.platform == 'emscripten', 'requires working subprocess'
)
def test_load_grammar_from_subprocess(self): def test_load_grammar_from_subprocess(self):
tmpdir = tempfile.mkdtemp() tmpdir = tempfile.mkdtemp()
tmpsubdir = os.path.join(tmpdir, 'subdir') tmpsubdir = os.path.join(tmpdir, 'subdir')

View file

@ -40,11 +40,12 @@ __all__ = [
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute", "bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
"requires_IEEE_754", "requires_zlib", "requires_IEEE_754", "requires_zlib",
"has_fork_support", "requires_fork", "has_fork_support", "requires_fork",
"has_subprocess_support", "requires_subprocess",
"anticipate_failure", "load_package_tests", "detect_api_mismatch", "anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__", "skip_if_buggy_ucrt_strfptime", "check__all__", "skip_if_buggy_ucrt_strfptime",
"check_disallow_instantiation", "check_disallow_instantiation",
# sys # sys
"is_jython", "is_android", "is_emscripten", "is_jython", "is_android", "is_emscripten", "is_wasi",
"check_impl_detail", "unix_shell", "setswitchinterval", "check_impl_detail", "unix_shell", "setswitchinterval",
# network # network
"open_urlresource", "open_urlresource",
@ -467,15 +468,23 @@ if sys.platform not in ('win32', 'vxworks'):
else: else:
unix_shell = None unix_shell = None
# wasm32-emscripten is POSIX-like but does not provide a # wasm32-emscripten and -wasi are POSIX-like but do not
# working fork() or subprocess API. # have subprocess or fork support.
is_emscripten = sys.platform == "emscripten" is_emscripten = sys.platform == "emscripten"
is_wasi = sys.platform == "wasi"
has_fork_support = hasattr(os, "fork") and not is_emscripten has_fork_support = hasattr(os, "fork") and not is_emscripten and not is_wasi
def requires_fork(): def requires_fork():
return unittest.skipUnless(has_fork_support, "requires working os.fork()") return unittest.skipUnless(has_fork_support, "requires working os.fork()")
has_subprocess_support = not is_emscripten and not is_wasi
def requires_subprocess():
"""Used for subprocess, os.spawn calls"""
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
# Define the URL of a dedicated HTTP server for the network tests. # Define the URL of a dedicated HTTP server for the network tests.
# The URL must use clear-text HTTP: no redirection to encrypted HTTPS. # The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
TEST_HTTP_URL = "http://www.pythontest.net" TEST_HTTP_URL = "http://www.pythontest.net"

View file

@ -42,6 +42,10 @@ def interpreter_requires_environment():
if 'PYTHONHOME' in os.environ: if 'PYTHONHOME' in os.environ:
__cached_interp_requires_environment = True __cached_interp_requires_environment = True
return True return True
# cannot run subprocess, assume we don't need it
if not support.has_subprocess_support:
__cached_interp_requires_environment = False
return False
# Try running an interpreter with -E to see if it works or not. # Try running an interpreter with -E to see if it works or not.
try: try:
@ -87,6 +91,7 @@ class _PythonRunResult(collections.namedtuple("_PythonRunResult",
# Executing the interpreter in a subprocess # Executing the interpreter in a subprocess
@support.requires_subprocess()
def run_python_until_end(*args, **env_vars): def run_python_until_end(*args, **env_vars):
env_required = interpreter_requires_environment() env_required = interpreter_requires_environment()
cwd = env_vars.pop('__cwd', None) cwd = env_vars.pop('__cwd', None)
@ -139,6 +144,7 @@ def run_python_until_end(*args, **env_vars):
return _PythonRunResult(rc, out, err), cmd_line return _PythonRunResult(rc, out, err), cmd_line
@support.requires_subprocess()
def _assert_python(expected_success, /, *args, **env_vars): def _assert_python(expected_success, /, *args, **env_vars):
res, cmd_line = run_python_until_end(*args, **env_vars) res, cmd_line = run_python_until_end(*args, **env_vars)
if (res.rc and expected_success) or (not res.rc and not expected_success): 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):
return _assert_python(False, *args, **env_vars) return _assert_python(False, *args, **env_vars)
@support.requires_subprocess()
def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw): def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
"""Run a Python subprocess with the given arguments. """Run a Python subprocess with the given arguments.
@ -273,6 +280,7 @@ def make_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename,
return zip_name, os.path.join(zip_name, script_name_in_zip) return zip_name, os.path.join(zip_name, script_name_in_zip)
@support.requires_subprocess()
def run_test_script(script): def run_test_script(script):
# use -u to try to get the full output if the test hangs or crash # use -u to try to get the full output if the test hangs or crash
if support.verbose: if support.verbose:

View file

@ -16,6 +16,8 @@ AUDIT_TESTS_PY = support.findfile("audit-tests.py")
class AuditTest(unittest.TestCase): class AuditTest(unittest.TestCase):
@support.requires_subprocess()
def do_test(self, *args): def do_test(self, *args):
with subprocess.Popen( with subprocess.Popen(
[sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args], [sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args],
@ -29,6 +31,7 @@ class AuditTest(unittest.TestCase):
if p.returncode: if p.returncode:
self.fail("".join(p.stderr)) self.fail("".join(p.stderr))
@support.requires_subprocess()
def run_python(self, *args): def run_python(self, *args):
events = [] events = []
with subprocess.Popen( with subprocess.Popen(

View file

@ -66,6 +66,7 @@ class CAPITest(unittest.TestCase):
self.assertEqual(testfunction.attribute, "test") self.assertEqual(testfunction.attribute, "test")
self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test") self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test")
@support.requires_subprocess()
def test_no_FatalError_infinite_loop(self): def test_no_FatalError_infinite_loop(self):
with support.SuppressCrashReport(): with support.SuppressCrashReport():
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",

View file

@ -15,6 +15,8 @@ from test.support.script_helper import (
interpreter_requires_environment interpreter_requires_environment
) )
if not support.has_subprocess_support:
raise unittest.SkipTest("test module requires subprocess")
# Debug build? # Debug build?
Py_DEBUG = hasattr(sys, "gettotalrefcount") Py_DEBUG = hasattr(sys, "gettotalrefcount")

View file

@ -17,6 +17,8 @@ import sysconfig
import tempfile import tempfile
import textwrap import textwrap
if not support.has_subprocess_support:
raise unittest.SkipTest("test module requires subprocess")
MS_WINDOWS = (os.name == 'nt') MS_WINDOWS = (os.name == 'nt')
MACOS = (sys.platform == 'darwin') MACOS = (sys.platform == 'darwin')

View file

@ -412,6 +412,7 @@ class FaultHandlerTests(unittest.TestCase):
finally: finally:
sys.stderr = orig_stderr sys.stderr = orig_stderr
@support.requires_subprocess()
def test_disabled_by_default(self): def test_disabled_by_default(self):
# By default, the module should be disabled # By default, the module should be disabled
code = "import faulthandler; print(faulthandler.is_enabled())" code = "import faulthandler; print(faulthandler.is_enabled())"
@ -420,6 +421,7 @@ class FaultHandlerTests(unittest.TestCase):
output = subprocess.check_output(args) output = subprocess.check_output(args)
self.assertEqual(output.rstrip(), b"False") self.assertEqual(output.rstrip(), b"False")
@support.requires_subprocess()
def test_sys_xoptions(self): def test_sys_xoptions(self):
# Test python -X faulthandler # Test python -X faulthandler
code = "import faulthandler; print(faulthandler.is_enabled())" code = "import faulthandler; print(faulthandler.is_enabled())"
@ -432,6 +434,7 @@ class FaultHandlerTests(unittest.TestCase):
output = subprocess.check_output(args, env=env) output = subprocess.check_output(args, env=env)
self.assertEqual(output.rstrip(), b"True") self.assertEqual(output.rstrip(), b"True")
@support.requires_subprocess()
def test_env_var(self): def test_env_var(self):
# empty env var # empty env var
code = "import faulthandler; print(faulthandler.is_enabled())" code = "import faulthandler; print(faulthandler.is_enabled())"

View file

@ -15,12 +15,15 @@ import subprocess
import sys import sys
import time import time
import unittest import unittest
from test import support
if not support.has_subprocess_support:
raise unittest.SkipTest("test module requires subprocess")
# Test import all of the things we're about to try testing up front. # Test import all of the things we're about to try testing up front.
import _io import _io
import _pyio import _pyio
@unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.') @unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.')
class TestFileIOSignalInterrupt: class TestFileIOSignalInterrupt:
def setUp(self): def setUp(self):

View file

@ -1,7 +1,7 @@
import unittest import unittest
import unittest.mock import unittest.mock
from test.support import (verbose, refcount_test, from test.support import (verbose, refcount_test,
cpython_only) cpython_only, requires_subprocess)
from test.support.import_helper import import_module from test.support.import_helper import import_module
from test.support.os_helper import temp_dir, TESTFN, unlink from test.support.os_helper import temp_dir, TESTFN, unlink
from test.support.script_helper import assert_python_ok, make_script from test.support.script_helper import assert_python_ok, make_script
@ -661,6 +661,7 @@ class GCTests(unittest.TestCase):
gc.collect() # this blows up (bad C pointer) when it fails gc.collect() # this blows up (bad C pointer) when it fails
@cpython_only @cpython_only
@requires_subprocess()
def test_garbage_at_shutdown(self): def test_garbage_at_shutdown(self):
import subprocess import subprocess
code = """if 1: code = """if 1:

View file

@ -12,7 +12,7 @@ import unittest
from subprocess import PIPE, Popen from subprocess import PIPE, Popen
from test.support import import_helper from test.support import import_helper
from test.support import os_helper from test.support import os_helper
from test.support import _4G, bigmemtest from test.support import _4G, bigmemtest, requires_subprocess
from test.support.script_helper import assert_python_ok, assert_python_failure from test.support.script_helper import assert_python_ok, assert_python_failure
gzip = import_helper.import_module('gzip') gzip = import_helper.import_module('gzip')
@ -760,6 +760,7 @@ def create_and_remove_directory(directory):
class TestCommandLine(unittest.TestCase): class TestCommandLine(unittest.TestCase):
data = b'This is a simple test with gzip' data = b'This is a simple test with gzip'
@requires_subprocess()
def test_decompress_stdin_stdout(self): def test_decompress_stdin_stdout(self):
with io.BytesIO() as bytes_io: with io.BytesIO() as bytes_io:
with gzip.GzipFile(fileobj=bytes_io, mode='wb') as gzip_file: with gzip.GzipFile(fileobj=bytes_io, mode='wb') as gzip_file:
@ -795,6 +796,7 @@ class TestCommandLine(unittest.TestCase):
self.assertEqual(rc, 1) self.assertEqual(rc, 1)
self.assertEqual(out, b'') self.assertEqual(out, b'')
@requires_subprocess()
@create_and_remove_directory(TEMPDIR) @create_and_remove_directory(TEMPDIR)
def test_compress_stdin_outfile(self): def test_compress_stdin_outfile(self):
args = sys.executable, '-m', 'gzip' args = sys.executable, '-m', 'gzip'

View file

@ -1096,6 +1096,7 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape') value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape')
self.assertEqual(os.environ['bytes'], value_str) self.assertEqual(os.environ['bytes'], value_str)
@support.requires_subprocess()
def test_putenv_unsetenv(self): def test_putenv_unsetenv(self):
name = "PYTHONTESTVAR" name = "PYTHONTESTVAR"
value = "testvalue" value = "testvalue"
@ -2279,6 +2280,7 @@ class PosixUidGidTests(unittest.TestCase):
self.assertRaises(OverflowError, os.setreuid, 0, self.UID_OVERFLOW) self.assertRaises(OverflowError, os.setreuid, 0, self.UID_OVERFLOW)
@unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()') @unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()')
@support.requires_subprocess()
def test_setreuid_neg1(self): def test_setreuid_neg1(self):
# Needs to accept -1. We run this in a subprocess to avoid # Needs to accept -1. We run this in a subprocess to avoid
# altering the test runner's process state (issue8045). # altering the test runner's process state (issue8045).
@ -2287,6 +2289,7 @@ class PosixUidGidTests(unittest.TestCase):
'import os,sys;os.setreuid(-1,-1);sys.exit(0)']) 'import os,sys;os.setreuid(-1,-1);sys.exit(0)'])
@unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()') @unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
@support.requires_subprocess()
def test_setregid(self): def test_setregid(self):
if os.getuid() != 0 and not HAVE_WHEEL_GROUP: if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
self.assertRaises(OSError, os.setregid, 0, 0) self.assertRaises(OSError, os.setregid, 0, 0)
@ -2296,6 +2299,7 @@ class PosixUidGidTests(unittest.TestCase):
self.assertRaises(OverflowError, os.setregid, 0, self.GID_OVERFLOW) self.assertRaises(OverflowError, os.setregid, 0, self.GID_OVERFLOW)
@unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()') @unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
@support.requires_subprocess()
def test_setregid_neg1(self): def test_setregid_neg1(self):
# Needs to accept -1. We run this in a subprocess to avoid # Needs to accept -1. We run this in a subprocess to avoid
# altering the test runner's process state (issue8045). # altering the test runner's process state (issue8045).
@ -2469,6 +2473,7 @@ class Win32KillTests(unittest.TestCase):
self.fail("subprocess did not stop on {}".format(name)) self.fail("subprocess did not stop on {}".format(name))
@unittest.skip("subprocesses aren't inheriting Ctrl+C property") @unittest.skip("subprocesses aren't inheriting Ctrl+C property")
@support.requires_subprocess()
def test_CTRL_C_EVENT(self): def test_CTRL_C_EVENT(self):
from ctypes import wintypes from ctypes import wintypes
import ctypes import ctypes
@ -2487,6 +2492,7 @@ class Win32KillTests(unittest.TestCase):
self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT") self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
@support.requires_subprocess()
def test_CTRL_BREAK_EVENT(self): def test_CTRL_BREAK_EVENT(self):
self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT") self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT")
@ -2924,6 +2930,7 @@ class DeviceEncodingTests(unittest.TestCase):
self.assertTrue(codecs.lookup(encoding)) self.assertTrue(codecs.lookup(encoding))
@support.requires_subprocess()
class PidTests(unittest.TestCase): class PidTests(unittest.TestCase):
@unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid") @unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")
def test_getppid(self): def test_getppid(self):
@ -2996,6 +3003,7 @@ class PidTests(unittest.TestCase):
self.check_waitpid(code, exitcode=-signum, callback=kill_process) self.check_waitpid(code, exitcode=-signum, callback=kill_process)
@support.requires_subprocess()
class SpawnTests(unittest.TestCase): class SpawnTests(unittest.TestCase):
def create_args(self, *, with_env=False, use_bytes=False): def create_args(self, *, with_env=False, use_bytes=False):
self.exitcode = 17 self.exitcode = 17

View file

@ -79,6 +79,7 @@ class PlatformTest(unittest.TestCase):
res = platform.architecture() res = platform.architecture()
@os_helper.skip_unless_symlink @os_helper.skip_unless_symlink
@support.requires_subprocess()
def test_architecture_via_symlink(self): # issue3762 def test_architecture_via_symlink(self): # issue3762
with support.PythonSymlink() as py: with support.PythonSymlink() as py:
cmd = "-c", "import platform; print(platform.architecture())" cmd = "-c", "import platform; print(platform.architecture())"
@ -269,6 +270,7 @@ class PlatformTest(unittest.TestCase):
self.assertEqual(res[:5], expected[:5]) self.assertEqual(res[:5], expected[:5])
@unittest.skipIf(sys.platform in ['win32', 'OpenVMS'], "uname -p not used") @unittest.skipIf(sys.platform in ['win32', 'OpenVMS'], "uname -p not used")
@support.requires_subprocess()
def test_uname_processor(self): def test_uname_processor(self):
""" """
On some systems, the processor must match the output On some systems, the processor must match the output

View file

@ -7,7 +7,7 @@ import select
import threading import threading
import time import time
import unittest import unittest
from test.support import cpython_only from test.support import cpython_only, requires_subprocess
from test.support import threading_helper from test.support import threading_helper
from test.support.os_helper import TESTFN from test.support.os_helper import TESTFN
@ -120,6 +120,7 @@ class PollTests(unittest.TestCase):
# Another test case for poll(). This is copied from the test case for # Another test case for poll(). This is copied from the test case for
# select(), modified to use poll() instead. # select(), modified to use poll() instead.
@requires_subprocess()
def test_poll2(self): def test_poll2(self):
cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,

View file

@ -19,6 +19,7 @@ python = sys.executable
if ' ' in python: if ' ' in python:
python = '"' + python + '"' # quote embedded space for cmdline python = '"' + python + '"' # quote embedded space for cmdline
@support.requires_subprocess()
class PopenTest(unittest.TestCase): class PopenTest(unittest.TestCase):
def _do_test_commandline(self, cmdline, expected): def _do_test_commandline(self, cmdline, expected):

View file

@ -230,6 +230,7 @@ class PyCompileCLITestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
os_helper.rmtree(self.directory) os_helper.rmtree(self.directory)
@support.requires_subprocess()
def pycompilecmd(self, *args, **kwargs): def pycompilecmd(self, *args, **kwargs):
# assert_python_* helpers don't return proc object. We'll just use # assert_python_* helpers don't return proc object. We'll just use
# subprocess.run() instead of spawn_python() and its friends to test # subprocess.run() instead of spawn_python() and its friends to test

View file

@ -3,6 +3,7 @@ import unittest
import sys, io, subprocess import sys, io, subprocess
import quopri import quopri
from test import support
ENCSAMPLE = b"""\ ENCSAMPLE = b"""\
@ -180,6 +181,7 @@ zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz''')
for p, e in self.HSTRINGS: for p, e in self.HSTRINGS:
self.assertEqual(quopri.decodestring(e, header=True), p) self.assertEqual(quopri.decodestring(e, header=True), p)
@support.requires_subprocess()
def test_scriptencode(self): def test_scriptencode(self):
(p, e) = self.STRINGS[-1] (p, e) = self.STRINGS[-1]
process = subprocess.Popen([sys.executable, "-mquopri"], process = subprocess.Popen([sys.executable, "-mquopri"],
@ -196,6 +198,7 @@ zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz''')
self.assertEqual(cout[i], e[i]) self.assertEqual(cout[i], e[i])
self.assertEqual(cout, e) self.assertEqual(cout, e)
@support.requires_subprocess()
def test_scriptdecode(self): def test_scriptdecode(self):
(p, e) = self.STRINGS[-1] (p, e) = self.STRINGS[-1]
process = subprocess.Popen([sys.executable, "-mquopri", "-d"], process = subprocess.Popen([sys.executable, "-mquopri", "-d"],

View file

@ -22,6 +22,8 @@ from test import support
from test.support import os_helper from test.support import os_helper
from test.libregrtest import utils, setup from test.libregrtest import utils, setup
if not support.has_subprocess_support:
raise unittest.SkipTest("test module requires subprocess")
Py_DEBUG = hasattr(sys, 'gettotalrefcount') Py_DEBUG = hasattr(sys, 'gettotalrefcount')
ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..') ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..')

View file

@ -5,9 +5,14 @@ import os
import unittest import unittest
import subprocess import subprocess
from textwrap import dedent from textwrap import dedent
from test.support import cpython_only, SuppressCrashReport from test.support import cpython_only, has_subprocess_support, SuppressCrashReport
from test.support.script_helper import kill_python from test.support.script_helper import kill_python
if not has_subprocess_support:
raise unittest.SkipTest("test module requires subprocess")
def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw): def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
"""Run the Python REPL with the given arguments. """Run the Python REPL with the given arguments.

View file

@ -12,7 +12,7 @@ import tempfile
import textwrap import textwrap
import unittest import unittest
import warnings import warnings
from test.support import no_tracing, verbose from test.support import no_tracing, verbose, requires_subprocess
from test.support.import_helper import forget, make_legacy_pyc, unload from test.support.import_helper import forget, make_legacy_pyc, unload
from test.support.os_helper import create_empty_file, temp_dir from test.support.os_helper import create_empty_file, temp_dir
from test.support.script_helper import make_script, make_zip_script from test.support.script_helper import make_script, make_zip_script
@ -781,6 +781,7 @@ class TestExit(unittest.TestCase):
) )
super().run(*args, **kwargs) super().run(*args, **kwargs)
@requires_subprocess()
def assertSigInt(self, *args, **kwargs): def assertSigInt(self, *args, **kwargs):
proc = subprocess.run(*args, **kwargs, text=True, stderr=subprocess.PIPE) proc = subprocess.run(*args, **kwargs, text=True, stderr=subprocess.PIPE)
self.assertTrue(proc.stderr.endswith("\nKeyboardInterrupt\n")) self.assertTrue(proc.stderr.endswith("\nKeyboardInterrupt\n"))

View file

@ -116,6 +116,7 @@ class PosixTests(unittest.TestCase):
self.assertLess(len(s), signal.NSIG) self.assertLess(len(s), signal.NSIG)
@unittest.skipUnless(sys.executable, "sys.executable required.") @unittest.skipUnless(sys.executable, "sys.executable required.")
@support.requires_subprocess()
def test_keyboard_interrupt_exit_code(self): def test_keyboard_interrupt_exit_code(self):
"""KeyboardInterrupt triggers exit via SIGINT.""" """KeyboardInterrupt triggers exit via SIGINT."""
process = subprocess.run( process = subprocess.run(
@ -166,6 +167,7 @@ class WindowsSignalTests(unittest.TestCase):
signal.signal(7, handler) signal.signal(7, handler)
@unittest.skipUnless(sys.executable, "sys.executable required.") @unittest.skipUnless(sys.executable, "sys.executable required.")
@support.requires_subprocess()
def test_keyboard_interrupt_exit_code(self): def test_keyboard_interrupt_exit_code(self):
"""KeyboardInterrupt triggers an exit using STATUS_CONTROL_C_EXIT.""" """KeyboardInterrupt triggers an exit using STATUS_CONTROL_C_EXIT."""
# We don't test via os.kill(os.getpid(), signal.CTRL_C_EVENT) here # We don't test via os.kill(os.getpid(), signal.CTRL_C_EVENT) here
@ -637,6 +639,7 @@ class WakeupSocketSignalTests(unittest.TestCase):
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows") @unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
@unittest.skipUnless(hasattr(signal, 'siginterrupt'), "needs signal.siginterrupt()") @unittest.skipUnless(hasattr(signal, 'siginterrupt'), "needs signal.siginterrupt()")
@support.requires_subprocess()
class SiginterruptTest(unittest.TestCase): class SiginterruptTest(unittest.TestCase):
def readpipe_interrupted(self, interrupt): def readpipe_interrupted(self, interrupt):

View file

@ -211,6 +211,7 @@ class HelperFunctionsTests(unittest.TestCase):
@unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 " @unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 "
"user-site (site.ENABLE_USER_SITE)") "user-site (site.ENABLE_USER_SITE)")
@support.requires_subprocess()
def test_s_option(self): def test_s_option(self):
# (ncoghlan) Change this to use script_helper... # (ncoghlan) Change this to use script_helper...
usersite = site.USER_SITE usersite = site.USER_SITE
@ -497,6 +498,7 @@ class ImportSideEffectTests(unittest.TestCase):
class StartupImportTests(unittest.TestCase): class StartupImportTests(unittest.TestCase):
@support.requires_subprocess()
def test_startup_imports(self): def test_startup_imports(self):
# Get sys.path in isolated mode (python3 -I) # Get sys.path in isolated mode (python3 -I)
popen = subprocess.Popen([sys.executable, '-X', 'utf8', '-I', popen = subprocess.Popen([sys.executable, '-X', 'utf8', '-I',
@ -547,17 +549,20 @@ class StartupImportTests(unittest.TestCase):
}.difference(sys.builtin_module_names) }.difference(sys.builtin_module_names)
self.assertFalse(modules.intersection(collection_mods), stderr) self.assertFalse(modules.intersection(collection_mods), stderr)
@support.requires_subprocess()
def test_startup_interactivehook(self): def test_startup_interactivehook(self):
r = subprocess.Popen([sys.executable, '-c', r = subprocess.Popen([sys.executable, '-c',
'import sys; sys.exit(hasattr(sys, "__interactivehook__"))']).wait() 'import sys; sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
self.assertTrue(r, "'__interactivehook__' not added by site") self.assertTrue(r, "'__interactivehook__' not added by site")
@support.requires_subprocess()
def test_startup_interactivehook_isolated(self): def test_startup_interactivehook_isolated(self):
# issue28192 readline is not automatically enabled in isolated mode # issue28192 readline is not automatically enabled in isolated mode
r = subprocess.Popen([sys.executable, '-I', '-c', r = subprocess.Popen([sys.executable, '-I', '-c',
'import sys; sys.exit(hasattr(sys, "__interactivehook__"))']).wait() 'import sys; sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
self.assertFalse(r, "'__interactivehook__' added in isolated mode") self.assertFalse(r, "'__interactivehook__' added in isolated mode")
@support.requires_subprocess()
def test_startup_interactivehook_isolated_explicit(self): def test_startup_interactivehook_isolated_explicit(self):
# issue28192 readline can be explicitly enabled in isolated mode # issue28192 readline can be explicitly enabled in isolated mode
r = subprocess.Popen([sys.executable, '-I', '-c', r = subprocess.Popen([sys.executable, '-I', '-c',
@ -607,6 +612,7 @@ class _pthFileTests(unittest.TestCase):
sys_path.append(abs_path) sys_path.append(abs_path)
return sys_path return sys_path
@support.requires_subprocess()
def test_underpth_basic(self): def test_underpth_basic(self):
libpath = test.support.STDLIB_DIR libpath = test.support.STDLIB_DIR
exe_prefix = os.path.dirname(sys.executable) exe_prefix = os.path.dirname(sys.executable)
@ -627,6 +633,7 @@ class _pthFileTests(unittest.TestCase):
"sys.path is incorrect" "sys.path is incorrect"
) )
@support.requires_subprocess()
def test_underpth_nosite_file(self): def test_underpth_nosite_file(self):
libpath = test.support.STDLIB_DIR libpath = test.support.STDLIB_DIR
exe_prefix = os.path.dirname(sys.executable) exe_prefix = os.path.dirname(sys.executable)
@ -655,6 +662,7 @@ class _pthFileTests(unittest.TestCase):
"sys.path is incorrect" "sys.path is incorrect"
) )
@support.requires_subprocess()
def test_underpth_file(self): def test_underpth_file(self):
libpath = test.support.STDLIB_DIR libpath = test.support.STDLIB_DIR
exe_prefix = os.path.dirname(sys.executable) exe_prefix = os.path.dirname(sys.executable)
@ -679,6 +687,7 @@ class _pthFileTests(unittest.TestCase):
)], env=env) )], env=env)
self.assertTrue(rc, "sys.path is incorrect") self.assertTrue(rc, "sys.path is incorrect")
@support.requires_subprocess()
def test_underpth_dll_file(self): def test_underpth_dll_file(self):
libpath = test.support.STDLIB_DIR libpath = test.support.STDLIB_DIR
exe_prefix = os.path.dirname(sys.executable) exe_prefix = os.path.dirname(sys.executable)

View file

@ -1,7 +1,7 @@
# -*- coding: koi8-r -*- # -*- coding: koi8-r -*-
import unittest import unittest
from test.support import script_helper, captured_stdout from test.support import script_helper, captured_stdout, requires_subprocess
from test.support.os_helper import TESTFN, unlink, rmtree from test.support.os_helper import TESTFN, unlink, rmtree
from test.support.import_helper import unload from test.support.import_helper import unload
import importlib import importlib
@ -65,6 +65,7 @@ class MiscSourceEncodingTest(unittest.TestCase):
# two bytes in common with the UTF-8 BOM # two bytes in common with the UTF-8 BOM
self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20') self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20')
@requires_subprocess()
def test_20731(self): def test_20731(self):
sub = subprocess.Popen([sys.executable, sub = subprocess.Popen([sys.executable,
os.path.join(os.path.dirname(__file__), os.path.join(os.path.dirname(__file__),

View file

@ -48,6 +48,9 @@ except:
if support.PGO: if support.PGO:
raise unittest.SkipTest("test is not helpful for PGO") raise unittest.SkipTest("test is not helpful for PGO")
if not support.has_subprocess_support:
raise unittest.SkipTest("test module requires subprocess")
mswindows = (sys.platform == "win32") mswindows = (sys.platform == "win32")
# #

View file

@ -491,6 +491,7 @@ class TestSupport(unittest.TestCase):
# pending child process # pending child process
support.reap_children() support.reap_children()
@support.requires_subprocess()
def check_options(self, args, func, expected=None): def check_options(self, args, func, expected=None):
code = f'from test.support import {func}; print(repr({func}()))' code = f'from test.support import {func}; print(repr({func}()))'
cmd = [sys.executable, *args, '-c', code] cmd = [sys.executable, *args, '-c', code]

View file

@ -694,6 +694,7 @@ class SysModuleTest(unittest.TestCase):
def test_clear_type_cache(self): def test_clear_type_cache(self):
sys._clear_type_cache() sys._clear_type_cache()
@support.requires_subprocess()
def test_ioencoding(self): def test_ioencoding(self):
env = dict(os.environ) env = dict(os.environ)
@ -741,6 +742,7 @@ class SysModuleTest(unittest.TestCase):
'requires OS support of non-ASCII encodings') 'requires OS support of non-ASCII encodings')
@unittest.skipUnless(sys.getfilesystemencoding() == locale.getpreferredencoding(False), @unittest.skipUnless(sys.getfilesystemencoding() == locale.getpreferredencoding(False),
'requires FS encoding to match locale') 'requires FS encoding to match locale')
@support.requires_subprocess()
def test_ioencoding_nonascii(self): def test_ioencoding_nonascii(self):
env = dict(os.environ) env = dict(os.environ)
@ -753,6 +755,7 @@ class SysModuleTest(unittest.TestCase):
@unittest.skipIf(sys.base_prefix != sys.prefix, @unittest.skipIf(sys.base_prefix != sys.prefix,
'Test is not venv-compatible') 'Test is not venv-compatible')
@support.requires_subprocess()
def test_executable(self): def test_executable(self):
# sys.executable should be absolute # sys.executable should be absolute
self.assertEqual(os.path.abspath(sys.executable), sys.executable) self.assertEqual(os.path.abspath(sys.executable), sys.executable)
@ -854,9 +857,11 @@ class SysModuleTest(unittest.TestCase):
'stdout: surrogateescape\n' 'stdout: surrogateescape\n'
'stderr: backslashreplace\n') 'stderr: backslashreplace\n')
@support.requires_subprocess()
def test_c_locale_surrogateescape(self): def test_c_locale_surrogateescape(self):
self.check_locale_surrogateescape('C') self.check_locale_surrogateescape('C')
@support.requires_subprocess()
def test_posix_locale_surrogateescape(self): def test_posix_locale_surrogateescape(self):
self.check_locale_surrogateescape('POSIX') self.check_locale_surrogateescape('POSIX')
@ -1005,6 +1010,7 @@ class SysModuleTest(unittest.TestCase):
self.assertIsInstance(level, int) self.assertIsInstance(level, int)
self.assertGreater(level, 0) self.assertGreater(level, 0)
@support.requires_subprocess()
def test_sys_tracebacklimit(self): def test_sys_tracebacklimit(self):
code = """if 1: code = """if 1:
import sys import sys
@ -1051,6 +1057,7 @@ class SysModuleTest(unittest.TestCase):
out = out.decode('ascii', 'replace').rstrip() out = out.decode('ascii', 'replace').rstrip()
self.assertEqual(out, 'mbcs replace') self.assertEqual(out, 'mbcs replace')
@support.requires_subprocess()
def test_orig_argv(self): def test_orig_argv(self):
code = textwrap.dedent(''' code = textwrap.dedent('''
import sys import sys

View file

@ -5,7 +5,7 @@ import subprocess
import shutil import shutil
from copy import copy from copy import copy
from test.support import (captured_stdout, PythonSymlink) from test.support import (captured_stdout, PythonSymlink, requires_subprocess)
from test.support.import_helper import import_module from test.support.import_helper import import_module
from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink, from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink,
change_cwd) change_cwd)
@ -273,6 +273,7 @@ class TestSysConfig(unittest.TestCase):
self.assertEqual(get_scheme_names(), tuple(sorted(wanted))) self.assertEqual(get_scheme_names(), tuple(sorted(wanted)))
@skip_unless_symlink @skip_unless_symlink
@requires_subprocess()
def test_symlink(self): # Issue 7880 def test_symlink(self): # Issue 7880
with PythonSymlink() as py: with PythonSymlink() as py:
cmd = "-c", "import sysconfig; print(sysconfig.get_platform())" cmd = "-c", "import sysconfig; print(sysconfig.get_platform())"
@ -326,6 +327,7 @@ class TestSysConfig(unittest.TestCase):
self.assertIn(ldflags, ldshared) self.assertIn(ldflags, ldshared)
@unittest.skipUnless(sys.platform == "darwin", "test only relevant on MacOSX") @unittest.skipUnless(sys.platform == "darwin", "test only relevant on MacOSX")
@requires_subprocess()
def test_platform_in_subprocess(self): def test_platform_in_subprocess(self):
my_platform = sysconfig.get_platform() my_platform = sysconfig.get_platform()

View file

@ -3,7 +3,7 @@ Tests for the threading module.
""" """
import test.support import test.support
from test.support import threading_helper from test.support import threading_helper, requires_subprocess
from test.support import verbose, cpython_only, os_helper from test.support import verbose, cpython_only, os_helper
from test.support.import_helper import import_module from test.support.import_helper import import_module
from test.support.script_helper import assert_python_ok, assert_python_failure from test.support.script_helper import assert_python_ok, assert_python_failure
@ -1259,6 +1259,7 @@ class ThreadingExceptionTests(BaseTestCase):
lock = threading.Lock() lock = threading.Lock()
self.assertRaises(RuntimeError, lock.release) self.assertRaises(RuntimeError, lock.release)
@requires_subprocess()
def test_recursion_limit(self): def test_recursion_limit(self):
# Issue 9670 # Issue 9670
# test that excessive recursion within a non-main thread causes # test that excessive recursion within a non-main thread causes

View file

@ -9,7 +9,8 @@ import unittest
import re import re
from test import support from test import support
from test.support import (Error, captured_output, cpython_only, ALWAYS_EQ, from test.support import (Error, captured_output, cpython_only, ALWAYS_EQ,
requires_debug_ranges, has_no_debug_ranges) requires_debug_ranges, has_no_debug_ranges,
requires_subprocess)
from test.support.os_helper import TESTFN, unlink from test.support.os_helper import TESTFN, unlink
from test.support.script_helper import assert_python_ok, assert_python_failure from test.support.script_helper import assert_python_ok, assert_python_failure
@ -203,6 +204,7 @@ class TracebackCases(unittest.TestCase):
str_name = '.'.join([X.__module__, X.__qualname__]) str_name = '.'.join([X.__module__, X.__qualname__])
self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value)) self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value))
@requires_subprocess()
def test_encoded_file(self): def test_encoded_file(self):
# Test that tracebacks are correctly printed for encoded source files: # Test that tracebacks are correctly printed for encoded source files:
# - correct line number (Issue2384) # - correct line number (Issue2384)

View file

@ -255,6 +255,7 @@ class UTF8ModeTests(unittest.TestCase):
@unittest.skipIf(MS_WINDOWS, @unittest.skipIf(MS_WINDOWS,
"os.device_encoding() doesn't implement " "os.device_encoding() doesn't implement "
"the UTF-8 Mode on Windows") "the UTF-8 Mode on Windows")
@support.requires_subprocess()
def test_device_encoding(self): def test_device_encoding(self):
# Use stdout as TTY # Use stdout as TTY
if not sys.stdout.isatty(): if not sys.stdout.isatty():

View file

@ -15,7 +15,8 @@ import subprocess
import sys import sys
import tempfile import tempfile
from test.support import (captured_stdout, captured_stderr, requires_zlib, from test.support import (captured_stdout, captured_stderr, requires_zlib,
skip_if_broken_multiprocessing_synchronize, verbose) skip_if_broken_multiprocessing_synchronize, verbose,
requires_subprocess)
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree) from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree)
import unittest import unittest
import venv import venv
@ -33,6 +34,7 @@ requireVenvCreate = unittest.skipUnless(
or sys._base_executable != sys.executable, or sys._base_executable != sys.executable,
'cannot run venv.create from within a venv on this platform') 'cannot run venv.create from within a venv on this platform')
@requires_subprocess()
def check_output(cmd, encoding=None): def check_output(cmd, encoding=None):
p = subprocess.Popen(cmd, p = subprocess.Popen(cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,

View file

@ -8,6 +8,8 @@ from test import support
from test.support import import_helper from test.support import import_helper
from test.support import os_helper from test.support import os_helper
if not support.has_subprocess_support:
raise unittest.SkipTest("test webserver requires subprocess")
URL = 'http://www.example.com' URL = 'http://www.example.com'
CMD_NAME = 'test' CMD_NAME = 'test'

View file

@ -21,7 +21,7 @@ from random import randint, random, randbytes
from test.support import script_helper from test.support import script_helper
from test.support import (findfile, requires_zlib, requires_bz2, from test.support import (findfile, requires_zlib, requires_bz2,
requires_lzma, captured_stdout) requires_lzma, captured_stdout, requires_subprocess)
from test.support.os_helper import TESTFN, unlink, rmtree, temp_dir, temp_cwd from test.support.os_helper import TESTFN, unlink, rmtree, temp_dir, temp_cwd
@ -2771,6 +2771,7 @@ class TestExecutablePrependedZip(unittest.TestCase):
@unittest.skipUnless(sys.executable, 'sys.executable required.') @unittest.skipUnless(sys.executable, 'sys.executable required.')
@unittest.skipUnless(os.access('/bin/bash', os.X_OK), @unittest.skipUnless(os.access('/bin/bash', os.X_OK),
'Test relies on #!/bin/bash working.') 'Test relies on #!/bin/bash working.')
@requires_subprocess()
def test_execute_zip2(self): def test_execute_zip2(self):
output = subprocess.check_output([self.exe_zip, sys.executable]) output = subprocess.check_output([self.exe_zip, sys.executable])
self.assertIn(b'number in executable: 5', output) self.assertIn(b'number in executable: 5', output)
@ -2778,6 +2779,7 @@ class TestExecutablePrependedZip(unittest.TestCase):
@unittest.skipUnless(sys.executable, 'sys.executable required.') @unittest.skipUnless(sys.executable, 'sys.executable required.')
@unittest.skipUnless(os.access('/bin/bash', os.X_OK), @unittest.skipUnless(os.access('/bin/bash', os.X_OK),
'Test relies on #!/bin/bash working.') 'Test relies on #!/bin/bash working.')
@requires_subprocess()
def test_execute_zip64(self): def test_execute_zip64(self):
output = subprocess.check_output([self.exe_zip64, sys.executable]) output = subprocess.check_output([self.exe_zip64, sys.executable])
self.assertIn(b'number in executable: 5', output) self.assertIn(b'number in executable: 5', output)

View file

@ -0,0 +1,3 @@
Add :func:`test.support.requires_subprocess` decorator to mark tests which
require working :mod:`subprocess` module or ``os.spawn*``. The
wasm32-emscripten platform has no support for processes.