Index: Lib/test/test_ioctl.py =================================================================== --- Lib/test/test_ioctl.py (revision 77754) +++ Lib/test/test_ioctl.py (working copy) @@ -7,9 +7,17 @@ try: tty = open("/dev/tty", "r") - tty.close() except IOError: raise unittest.SkipTest("Unable to open /dev/tty") +else: + # Skip if another process is in foreground + r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") + tty.close() + rpgrp = struct.unpack("i", r)[0] + if rpgrp not in (os.getpgrp(), os.getsid(0)): + raise unittest.SkipTest("Process group %s is associated " + "with /dev/tty" % rpgrp) + del tty, r, rpgrp try: import pty