summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-01-25 07:09:06 (GMT)
committerGitHub <noreply@github.com>2022-01-25 07:09:06 (GMT)
commit8464fbc42ecc9ce504faac499711dcdc6eedef16 (patch)
tree1992e76c83da4720bc1dbc95901a417e0a4781e3 /Lib/test
parente1abffca45b60729c460e3e2ad50c8c1946cfd4e (diff)
downloadcpython-8464fbc42ecc9ce504faac499711dcdc6eedef16.zip
cpython-8464fbc42ecc9ce504faac499711dcdc6eedef16.tar.gz
cpython-8464fbc42ecc9ce504faac499711dcdc6eedef16.tar.bz2
bpo-40280: Skip subprocess-based tests on wasm32-emscripten (GH-30615)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/support/__init__.py17
-rw-r--r--Lib/test/support/script_helper.py8
-rw-r--r--Lib/test/test_audit.py3
-rw-r--r--Lib/test/test_capi.py1
-rw-r--r--Lib/test/test_cmd_line.py2
-rw-r--r--Lib/test/test_embed.py2
-rw-r--r--Lib/test/test_faulthandler.py3
-rw-r--r--Lib/test/test_file_eintr.py5
-rw-r--r--Lib/test/test_gc.py3
-rw-r--r--Lib/test/test_gzip.py4
-rw-r--r--Lib/test/test_os.py8
-rw-r--r--Lib/test/test_platform.py2
-rw-r--r--Lib/test/test_poll.py3
-rw-r--r--Lib/test/test_popen.py1
-rw-r--r--Lib/test/test_py_compile.py1
-rw-r--r--Lib/test/test_quopri.py3
-rw-r--r--Lib/test/test_regrtest.py2
-rw-r--r--Lib/test/test_repl.py7
-rw-r--r--Lib/test/test_runpy.py3
-rw-r--r--Lib/test/test_signal.py3
-rw-r--r--Lib/test/test_site.py9
-rw-r--r--Lib/test/test_source_encoding.py3
-rw-r--r--Lib/test/test_subprocess.py3
-rw-r--r--Lib/test/test_support.py1
-rw-r--r--Lib/test/test_sys.py7
-rw-r--r--Lib/test/test_sysconfig.py4
-rw-r--r--Lib/test/test_threading.py3
-rw-r--r--Lib/test/test_traceback.py4
-rw-r--r--Lib/test/test_utf8_mode.py1
-rw-r--r--Lib/test/test_venv.py4
-rw-r--r--Lib/test/test_webbrowser.py2
-rw-r--r--Lib/test/test_zipfile.py4
32 files changed, 110 insertions, 16 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index ca903d3..1e4935f 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -40,11 +40,12 @@ __all__ = [
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
"requires_IEEE_754", "requires_zlib",
"has_fork_support", "requires_fork",
+ "has_subprocess_support", "requires_subprocess",
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__", "skip_if_buggy_ucrt_strfptime",
"check_disallow_instantiation",
# sys
- "is_jython", "is_android", "is_emscripten",
+ "is_jython", "is_android", "is_emscripten", "is_wasi",
"check_impl_detail", "unix_shell", "setswitchinterval",
# network
"open_urlresource",
@@ -467,15 +468,23 @@ if sys.platform not in ('win32', 'vxworks'):
else:
unix_shell = None
-# wasm32-emscripten is POSIX-like but does not provide a
-# working fork() or subprocess API.
+# wasm32-emscripten and -wasi are POSIX-like but do not
+# have subprocess or fork support.
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():
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.
# The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
TEST_HTTP_URL = "http://www.pythontest.net"
diff --git a/Lib/test/support/script_helper.py b/Lib/test/support/script_helper.py
index 6d699c8..c2b43f4 100644
--- a/Lib/test/support/script_helper.py
+++ b/Lib/test/support/script_helper.py
@@ -42,6 +42,10 @@ def interpreter_requires_environment():
if 'PYTHONHOME' in os.environ:
__cached_interp_requires_environment = 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:
@@ -87,6 +91,7 @@ class _PythonRunResult(collections.namedtuple("_PythonRunResult",
# Executing the interpreter in a subprocess
+@support.requires_subprocess()
def run_python_until_end(*args, **env_vars):
env_required = interpreter_requires_environment()
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
+@support.requires_subprocess()
def _assert_python(expected_success, /, *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):
@@ -171,6 +177,7 @@ def assert_python_failure(*args, **env_vars):
return _assert_python(False, *args, **env_vars)
+@support.requires_subprocess()
def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
"""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)
+@support.requires_subprocess()
def run_test_script(script):
# use -u to try to get the full output if the test hangs or crash
if support.verbose:
diff --git a/Lib/test/test_audit.py b/Lib/test/test_audit.py
index d99b3b7..0fa2d74 100644
--- a/Lib/test/test_audit.py
+++ b/Lib/test/test_audit.py
@@ -16,6 +16,8 @@ AUDIT_TESTS_PY = support.findfile("audit-tests.py")
class AuditTest(unittest.TestCase):
+
+ @support.requires_subprocess()
def do_test(self, *args):
with subprocess.Popen(
[sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args],
@@ -29,6 +31,7 @@ class AuditTest(unittest.TestCase):
if p.returncode:
self.fail("".join(p.stderr))
+ @support.requires_subprocess()
def run_python(self, *args):
events = []
with subprocess.Popen(
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 0957f32..a5db8a1 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -66,6 +66,7 @@ class CAPITest(unittest.TestCase):
self.assertEqual(testfunction.attribute, "test")
self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test")
+ @support.requires_subprocess()
def test_no_FatalError_infinite_loop(self):
with support.SuppressCrashReport():
p = subprocess.Popen([sys.executable, "-c",
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index fa5f39e..352109e 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -15,6 +15,8 @@ from test.support.script_helper import (
interpreter_requires_environment
)
+if not support.has_subprocess_support:
+ raise unittest.SkipTest("test module requires subprocess")
# Debug build?
Py_DEBUG = hasattr(sys, "gettotalrefcount")
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 19c53c3..15c6b05 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -17,6 +17,8 @@ import sysconfig
import tempfile
import textwrap
+if not support.has_subprocess_support:
+ raise unittest.SkipTest("test module requires subprocess")
MS_WINDOWS = (os.name == 'nt')
MACOS = (sys.platform == 'darwin')
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
index de986a3..f7eaa77 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -412,6 +412,7 @@ class FaultHandlerTests(unittest.TestCase):
finally:
sys.stderr = orig_stderr
+ @support.requires_subprocess()
def test_disabled_by_default(self):
# By default, the module should be disabled
code = "import faulthandler; print(faulthandler.is_enabled())"
@@ -420,6 +421,7 @@ class FaultHandlerTests(unittest.TestCase):
output = subprocess.check_output(args)
self.assertEqual(output.rstrip(), b"False")
+ @support.requires_subprocess()
def test_sys_xoptions(self):
# Test python -X faulthandler
code = "import faulthandler; print(faulthandler.is_enabled())"
@@ -432,6 +434,7 @@ class FaultHandlerTests(unittest.TestCase):
output = subprocess.check_output(args, env=env)
self.assertEqual(output.rstrip(), b"True")
+ @support.requires_subprocess()
def test_env_var(self):
# empty env var
code = "import faulthandler; print(faulthandler.is_enabled())"
diff --git a/Lib/test/test_file_eintr.py b/Lib/test/test_file_eintr.py
index 01408d8..f9236f4 100644
--- a/Lib/test/test_file_eintr.py
+++ b/Lib/test/test_file_eintr.py
@@ -15,12 +15,15 @@ import subprocess
import sys
import time
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.
import _io
import _pyio
-
@unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.')
class TestFileIOSignalInterrupt:
def setUp(self):
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index 52948f1..c4d4355 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -1,7 +1,7 @@
import unittest
import unittest.mock
from test.support import (verbose, refcount_test,
- cpython_only)
+ cpython_only, requires_subprocess)
from test.support.import_helper import import_module
from test.support.os_helper import temp_dir, TESTFN, unlink
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
@cpython_only
+ @requires_subprocess()
def test_garbage_at_shutdown(self):
import subprocess
code = """if 1:
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index aa66d2f..497e66c 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -12,7 +12,7 @@ import unittest
from subprocess import PIPE, Popen
from test.support import import_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
gzip = import_helper.import_module('gzip')
@@ -760,6 +760,7 @@ def create_and_remove_directory(directory):
class TestCommandLine(unittest.TestCase):
data = b'This is a simple test with gzip'
+ @requires_subprocess()
def test_decompress_stdin_stdout(self):
with io.BytesIO() as bytes_io:
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(out, b'')
+ @requires_subprocess()
@create_and_remove_directory(TEMPDIR)
def test_compress_stdin_outfile(self):
args = sys.executable, '-m', 'gzip'
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 89e5e41..84c27f3 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1096,6 +1096,7 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape')
self.assertEqual(os.environ['bytes'], value_str)
+ @support.requires_subprocess()
def test_putenv_unsetenv(self):
name = "PYTHONTESTVAR"
value = "testvalue"
@@ -2279,6 +2280,7 @@ class PosixUidGidTests(unittest.TestCase):
self.assertRaises(OverflowError, os.setreuid, 0, self.UID_OVERFLOW)
@unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()')
+ @support.requires_subprocess()
def test_setreuid_neg1(self):
# Needs to accept -1. We run this in a subprocess to avoid
# 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)'])
@unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
+ @support.requires_subprocess()
def test_setregid(self):
if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
self.assertRaises(OSError, os.setregid, 0, 0)
@@ -2296,6 +2299,7 @@ class PosixUidGidTests(unittest.TestCase):
self.assertRaises(OverflowError, os.setregid, 0, self.GID_OVERFLOW)
@unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
+ @support.requires_subprocess()
def test_setregid_neg1(self):
# Needs to accept -1. We run this in a subprocess to avoid
# 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))
@unittest.skip("subprocesses aren't inheriting Ctrl+C property")
+ @support.requires_subprocess()
def test_CTRL_C_EVENT(self):
from ctypes import wintypes
import ctypes
@@ -2487,6 +2492,7 @@ class Win32KillTests(unittest.TestCase):
self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
+ @support.requires_subprocess()
def test_CTRL_BREAK_EVENT(self):
self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT")
@@ -2924,6 +2930,7 @@ class DeviceEncodingTests(unittest.TestCase):
self.assertTrue(codecs.lookup(encoding))
+@support.requires_subprocess()
class PidTests(unittest.TestCase):
@unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")
def test_getppid(self):
@@ -2996,6 +3003,7 @@ class PidTests(unittest.TestCase):
self.check_waitpid(code, exitcode=-signum, callback=kill_process)
+@support.requires_subprocess()
class SpawnTests(unittest.TestCase):
def create_args(self, *, with_env=False, use_bytes=False):
self.exitcode = 17
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
index 1a68877..d70ef15 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -79,6 +79,7 @@ class PlatformTest(unittest.TestCase):
res = platform.architecture()
@os_helper.skip_unless_symlink
+ @support.requires_subprocess()
def test_architecture_via_symlink(self): # issue3762
with support.PythonSymlink() as py:
cmd = "-c", "import platform; print(platform.architecture())"
@@ -269,6 +270,7 @@ class PlatformTest(unittest.TestCase):
self.assertEqual(res[:5], expected[:5])
@unittest.skipIf(sys.platform in ['win32', 'OpenVMS'], "uname -p not used")
+ @support.requires_subprocess()
def test_uname_processor(self):
"""
On some systems, the processor must match the output
diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py
index 82bbb3a..ae3ffc7 100644
--- a/Lib/test/test_poll.py
+++ b/Lib/test/test_poll.py
@@ -7,7 +7,7 @@ import select
import threading
import time
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.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
# select(), modified to use poll() instead.
+ @requires_subprocess()
def test_poll2(self):
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,
diff --git a/Lib/test/test_popen.py b/Lib/test/test_popen.py
index cac2f61..e6bfc48 100644
--- a/Lib/test/test_popen.py
+++ b/Lib/test/test_popen.py
@@ -19,6 +19,7 @@ python = sys.executable
if ' ' in python:
python = '"' + python + '"' # quote embedded space for cmdline
+@support.requires_subprocess()
class PopenTest(unittest.TestCase):
def _do_test_commandline(self, cmdline, expected):
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
index 5ed98db..794d643 100644
--- a/Lib/test/test_py_compile.py
+++ b/Lib/test/test_py_compile.py
@@ -230,6 +230,7 @@ class PyCompileCLITestCase(unittest.TestCase):
def tearDown(self):
os_helper.rmtree(self.directory)
+ @support.requires_subprocess()
def pycompilecmd(self, *args, **kwargs):
# assert_python_* helpers don't return proc object. We'll just use
# subprocess.run() instead of spawn_python() and its friends to test
diff --git a/Lib/test/test_quopri.py b/Lib/test/test_quopri.py
index 715544c..152d185 100644
--- a/Lib/test/test_quopri.py
+++ b/Lib/test/test_quopri.py
@@ -3,6 +3,7 @@ import unittest
import sys, io, subprocess
import quopri
+from test import support
ENCSAMPLE = b"""\
@@ -180,6 +181,7 @@ zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz''')
for p, e in self.HSTRINGS:
self.assertEqual(quopri.decodestring(e, header=True), p)
+ @support.requires_subprocess()
def test_scriptencode(self):
(p, e) = self.STRINGS[-1]
process = subprocess.Popen([sys.executable, "-mquopri"],
@@ -196,6 +198,7 @@ zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz''')
self.assertEqual(cout[i], e[i])
self.assertEqual(cout, e)
+ @support.requires_subprocess()
def test_scriptdecode(self):
(p, e) = self.STRINGS[-1]
process = subprocess.Popen([sys.executable, "-mquopri", "-d"],
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 08e2c87..babc8a6 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -22,6 +22,8 @@ from test import support
from test.support import os_helper
from test.libregrtest import utils, setup
+if not support.has_subprocess_support:
+ raise unittest.SkipTest("test module requires subprocess")
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..')
diff --git a/Lib/test/test_repl.py b/Lib/test/test_repl.py
index a8d04a4..ddb4aa6 100644
--- a/Lib/test/test_repl.py
+++ b/Lib/test/test_repl.py
@@ -5,9 +5,14 @@ import os
import unittest
import subprocess
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
+
+if not has_subprocess_support:
+ raise unittest.SkipTest("test module requires subprocess")
+
+
def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
"""Run the Python REPL with the given arguments.
diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py
index 2954dfe..80e695a 100644
--- a/Lib/test/test_runpy.py
+++ b/Lib/test/test_runpy.py
@@ -12,7 +12,7 @@ import tempfile
import textwrap
import unittest
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.os_helper import create_empty_file, temp_dir
from test.support.script_helper import make_script, make_zip_script
@@ -781,6 +781,7 @@ class TestExit(unittest.TestCase):
)
super().run(*args, **kwargs)
+ @requires_subprocess()
def assertSigInt(self, *args, **kwargs):
proc = subprocess.run(*args, **kwargs, text=True, stderr=subprocess.PIPE)
self.assertTrue(proc.stderr.endswith("\nKeyboardInterrupt\n"))
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index ac4626d..09de608 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -116,6 +116,7 @@ class PosixTests(unittest.TestCase):
self.assertLess(len(s), signal.NSIG)
@unittest.skipUnless(sys.executable, "sys.executable required.")
+ @support.requires_subprocess()
def test_keyboard_interrupt_exit_code(self):
"""KeyboardInterrupt triggers exit via SIGINT."""
process = subprocess.run(
@@ -166,6 +167,7 @@ class WindowsSignalTests(unittest.TestCase):
signal.signal(7, handler)
@unittest.skipUnless(sys.executable, "sys.executable required.")
+ @support.requires_subprocess()
def test_keyboard_interrupt_exit_code(self):
"""KeyboardInterrupt triggers an exit using STATUS_CONTROL_C_EXIT."""
# 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.skipUnless(hasattr(signal, 'siginterrupt'), "needs signal.siginterrupt()")
+@support.requires_subprocess()
class SiginterruptTest(unittest.TestCase):
def readpipe_interrupted(self, interrupt):
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index c54d868..032a1be 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -211,6 +211,7 @@ class HelperFunctionsTests(unittest.TestCase):
@unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 "
"user-site (site.ENABLE_USER_SITE)")
+ @support.requires_subprocess()
def test_s_option(self):
# (ncoghlan) Change this to use script_helper...
usersite = site.USER_SITE
@@ -497,6 +498,7 @@ class ImportSideEffectTests(unittest.TestCase):
class StartupImportTests(unittest.TestCase):
+ @support.requires_subprocess()
def test_startup_imports(self):
# Get sys.path in isolated mode (python3 -I)
popen = subprocess.Popen([sys.executable, '-X', 'utf8', '-I',
@@ -547,17 +549,20 @@ class StartupImportTests(unittest.TestCase):
}.difference(sys.builtin_module_names)
self.assertFalse(modules.intersection(collection_mods), stderr)
+ @support.requires_subprocess()
def test_startup_interactivehook(self):
r = subprocess.Popen([sys.executable, '-c',
'import sys; sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
self.assertTrue(r, "'__interactivehook__' not added by site")
+ @support.requires_subprocess()
def test_startup_interactivehook_isolated(self):
# issue28192 readline is not automatically enabled in isolated mode
r = subprocess.Popen([sys.executable, '-I', '-c',
'import sys; sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
self.assertFalse(r, "'__interactivehook__' added in isolated mode")
+ @support.requires_subprocess()
def test_startup_interactivehook_isolated_explicit(self):
# issue28192 readline can be explicitly enabled in isolated mode
r = subprocess.Popen([sys.executable, '-I', '-c',
@@ -607,6 +612,7 @@ class _pthFileTests(unittest.TestCase):
sys_path.append(abs_path)
return sys_path
+ @support.requires_subprocess()
def test_underpth_basic(self):
libpath = test.support.STDLIB_DIR
exe_prefix = os.path.dirname(sys.executable)
@@ -627,6 +633,7 @@ class _pthFileTests(unittest.TestCase):
"sys.path is incorrect"
)
+ @support.requires_subprocess()
def test_underpth_nosite_file(self):
libpath = test.support.STDLIB_DIR
exe_prefix = os.path.dirname(sys.executable)
@@ -655,6 +662,7 @@ class _pthFileTests(unittest.TestCase):
"sys.path is incorrect"
)
+ @support.requires_subprocess()
def test_underpth_file(self):
libpath = test.support.STDLIB_DIR
exe_prefix = os.path.dirname(sys.executable)
@@ -679,6 +687,7 @@ class _pthFileTests(unittest.TestCase):
)], env=env)
self.assertTrue(rc, "sys.path is incorrect")
+ @support.requires_subprocess()
def test_underpth_dll_file(self):
libpath = test.support.STDLIB_DIR
exe_prefix = os.path.dirname(sys.executable)
diff --git a/Lib/test/test_source_encoding.py b/Lib/test/test_source_encoding.py
index a0cb605..a0375fd 100644
--- a/Lib/test/test_source_encoding.py
+++ b/Lib/test/test_source_encoding.py
@@ -1,7 +1,7 @@
# -*- coding: koi8-r -*-
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.import_helper import unload
import importlib
@@ -65,6 +65,7 @@ class MiscSourceEncodingTest(unittest.TestCase):
# two bytes in common with the UTF-8 BOM
self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20')
+ @requires_subprocess()
def test_20731(self):
sub = subprocess.Popen([sys.executable,
os.path.join(os.path.dirname(__file__),
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 3af523e..99a25e2 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -48,6 +48,9 @@ except:
if support.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")
#
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 4dac7f6..1ce3c82 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -491,6 +491,7 @@ class TestSupport(unittest.TestCase):
# pending child process
support.reap_children()
+ @support.requires_subprocess()
def check_options(self, args, func, expected=None):
code = f'from test.support import {func}; print(repr({func}()))'
cmd = [sys.executable, *args, '-c', code]
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index f6da57f..41c4618 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -694,6 +694,7 @@ class SysModuleTest(unittest.TestCase):
def test_clear_type_cache(self):
sys._clear_type_cache()
+ @support.requires_subprocess()
def test_ioencoding(self):
env = dict(os.environ)
@@ -741,6 +742,7 @@ class SysModuleTest(unittest.TestCase):
'requires OS support of non-ASCII encodings')
@unittest.skipUnless(sys.getfilesystemencoding() == locale.getpreferredencoding(False),
'requires FS encoding to match locale')
+ @support.requires_subprocess()
def test_ioencoding_nonascii(self):
env = dict(os.environ)
@@ -753,6 +755,7 @@ class SysModuleTest(unittest.TestCase):
@unittest.skipIf(sys.base_prefix != sys.prefix,
'Test is not venv-compatible')
+ @support.requires_subprocess()
def test_executable(self):
# sys.executable should be absolute
self.assertEqual(os.path.abspath(sys.executable), sys.executable)
@@ -854,9 +857,11 @@ class SysModuleTest(unittest.TestCase):
'stdout: surrogateescape\n'
'stderr: backslashreplace\n')
+ @support.requires_subprocess()
def test_c_locale_surrogateescape(self):
self.check_locale_surrogateescape('C')
+ @support.requires_subprocess()
def test_posix_locale_surrogateescape(self):
self.check_locale_surrogateescape('POSIX')
@@ -1005,6 +1010,7 @@ class SysModuleTest(unittest.TestCase):
self.assertIsInstance(level, int)
self.assertGreater(level, 0)
+ @support.requires_subprocess()
def test_sys_tracebacklimit(self):
code = """if 1:
import sys
@@ -1051,6 +1057,7 @@ class SysModuleTest(unittest.TestCase):
out = out.decode('ascii', 'replace').rstrip()
self.assertEqual(out, 'mbcs replace')
+ @support.requires_subprocess()
def test_orig_argv(self):
code = textwrap.dedent('''
import sys
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index 6fbb80d..80fe9c8 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -5,7 +5,7 @@ import subprocess
import shutil
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.os_helper import (TESTFN, unlink, skip_unless_symlink,
change_cwd)
@@ -273,6 +273,7 @@ class TestSysConfig(unittest.TestCase):
self.assertEqual(get_scheme_names(), tuple(sorted(wanted)))
@skip_unless_symlink
+ @requires_subprocess()
def test_symlink(self): # Issue 7880
with PythonSymlink() as py:
cmd = "-c", "import sysconfig; print(sysconfig.get_platform())"
@@ -326,6 +327,7 @@ class TestSysConfig(unittest.TestCase):
self.assertIn(ldflags, ldshared)
@unittest.skipUnless(sys.platform == "darwin", "test only relevant on MacOSX")
+ @requires_subprocess()
def test_platform_in_subprocess(self):
my_platform = sysconfig.get_platform()
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index f03a642..48305714 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -3,7 +3,7 @@ Tests for the threading module.
"""
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_helper import import_module
from test.support.script_helper import assert_python_ok, assert_python_failure
@@ -1259,6 +1259,7 @@ class ThreadingExceptionTests(BaseTestCase):
lock = threading.Lock()
self.assertRaises(RuntimeError, lock.release)
+ @requires_subprocess()
def test_recursion_limit(self):
# Issue 9670
# test that excessive recursion within a non-main thread causes
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 966ff2a..e0884fb 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -9,7 +9,8 @@ import unittest
import re
from test import support
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.script_helper import assert_python_ok, assert_python_failure
@@ -203,6 +204,7 @@ class TracebackCases(unittest.TestCase):
str_name = '.'.join([X.__module__, X.__qualname__])
self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value))
+ @requires_subprocess()
def test_encoded_file(self):
# Test that tracebacks are correctly printed for encoded source files:
# - correct line number (Issue2384)
diff --git a/Lib/test/test_utf8_mode.py b/Lib/test/test_utf8_mode.py
index 8b6332e..2b96f76 100644
--- a/Lib/test/test_utf8_mode.py
+++ b/Lib/test/test_utf8_mode.py
@@ -255,6 +255,7 @@ class UTF8ModeTests(unittest.TestCase):
@unittest.skipIf(MS_WINDOWS,
"os.device_encoding() doesn't implement "
"the UTF-8 Mode on Windows")
+ @support.requires_subprocess()
def test_device_encoding(self):
# Use stdout as TTY
if not sys.stdout.isatty():
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index ca37abc..043158c 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -15,7 +15,8 @@ import subprocess
import sys
import tempfile
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)
import unittest
import venv
@@ -33,6 +34,7 @@ requireVenvCreate = unittest.skipUnless(
or sys._base_executable != sys.executable,
'cannot run venv.create from within a venv on this platform')
+@requires_subprocess()
def check_output(cmd, encoding=None):
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
diff --git a/Lib/test/test_webbrowser.py b/Lib/test/test_webbrowser.py
index dbfd2e5..9d608d6 100644
--- a/Lib/test/test_webbrowser.py
+++ b/Lib/test/test_webbrowser.py
@@ -8,6 +8,8 @@ from test import support
from test.support import import_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'
CMD_NAME = 'test'
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index df48fab..e226dd7 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -21,7 +21,7 @@ from random import randint, random, randbytes
from test.support import script_helper
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
@@ -2771,6 +2771,7 @@ class TestExecutablePrependedZip(unittest.TestCase):
@unittest.skipUnless(sys.executable, 'sys.executable required.')
@unittest.skipUnless(os.access('/bin/bash', os.X_OK),
'Test relies on #!/bin/bash working.')
+ @requires_subprocess()
def test_execute_zip2(self):
output = subprocess.check_output([self.exe_zip, sys.executable])
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(os.access('/bin/bash', os.X_OK),
'Test relies on #!/bin/bash working.')
+ @requires_subprocess()
def test_execute_zip64(self):
output = subprocess.check_output([self.exe_zip64, sys.executable])
self.assertIn(b'number in executable: 5', output)