bpo-36013: delete fragile interactive shell SIGINT test (GH-11902) · python/cpython@414c625

@@ -83,42 +83,16 @@ def test_keyboard_interrupt_exit_code(self):

8383

"""KeyboardInterrupt triggers exit via SIGINT."""

8484

process = subprocess.run(

8585

[sys.executable, "-c",

86-

"import os,signal; os.kill(os.getpid(), signal.SIGINT)"],

86+

"import os, signal, time\n"

87+

"os.kill(os.getpid(), signal.SIGINT)\n"

88+

"for _ in range(999): time.sleep(0.01)"],

8789

stderr=subprocess.PIPE)

8890

self.assertIn(b"KeyboardInterrupt", process.stderr)

8991

self.assertEqual(process.returncode, -signal.SIGINT)

90-91-

@unittest.skipUnless(sys.executable, "sys.executable required.")

92-

def test_keyboard_interrupt_communicated_to_shell(self):

93-

"""KeyboardInterrupt exits such that shells detect a ^C."""

94-

try:

95-

bash_proc = subprocess.run(

96-

["bash", "-c", 'echo "${BASH_VERSION}"'],

97-

stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)

98-

except OSError:

99-

raise unittest.SkipTest("bash required.")

100-

if bash_proc.returncode:

101-

raise unittest.SkipTest("could not determine bash version.")

102-

bash_ver = bash_proc.stdout.decode("ascii").strip()

103-

bash_major_minor = [int(n) for n in bash_ver.split(".", 2)[:2]]

104-

if bash_major_minor < [4, 4]:

105-

# In older versions of bash, -i does not work as needed

106-

# _for this automated test_. Older shells do behave as

107-

# expected in manual interactive use.

108-

raise unittest.SkipTest(f"bash version {bash_ver} is too old.")

109-

# The motivation for https://bugs.python.org/issue1054041.

110-

# An _interactive_ shell (bash -i simulates that here) detects

111-

# when a command exits via ^C and stops executing further

112-

# commands.

113-

process = subprocess.run(

114-

["bash", "-ic",

115-

f"{sys.executable} -c 'import os,signal; os.kill(os.getpid(), signal.SIGINT)'; "

116-

"echo TESTFAIL using bash \"${BASH_VERSION}\""],

117-

stderr=subprocess.PIPE, stdout=subprocess.PIPE)

118-

self.assertIn(b"KeyboardInterrupt", process.stderr)

119-

# An interactive shell will abort if python exits properly to

120-

# indicate that a KeyboardInterrupt occurred.

121-

self.assertNotIn(b"TESTFAIL", process.stdout)

92+

# Caveat: The exit code is insufficient to guarantee we actually died

93+

# via a signal. POSIX shells do more than look at the 8 bit value.

94+

# Writing an automation friendly test of an interactive shell

95+

# to confirm that our process died via a SIGINT proved too complex.

122961239712498

@unittest.skipUnless(sys.platform == "win32", "Windows specific")