]> granicus.if.org Git - python/commitdiff
Issue #7564: Skip test_ioctl if another process is attached to /dev/tty.
authorFlorent Xicluna <florent.xicluna@gmail.com>
Sun, 8 Aug 2010 18:06:13 +0000 (18:06 +0000)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Sun, 8 Aug 2010 18:06:13 +0000 (18:06 +0000)
Lib/test/test_ioctl.py
Misc/NEWS

index 47e591152303ec90c45449e5519b51a6cb094f3b..07dac09d8660f372a9b92433d6afd711b8d841c8 100644 (file)
@@ -7,9 +7,17 @@ get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
 
 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("Neither the process group nor the session "
+                                "are attached to /dev/tty")
+    del tty, r, rpgrp
 
 try:
     import pty
index 318b826d21e75ffb81f6c1ae5cb9889390ad497b..c6795a249aad71e9b0b7950b32acf71c30928291 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -136,6 +136,8 @@ Tools/Demos
 Tests
 -----
 
+- Issue #7564: Skip test_ioctl if another process is attached to /dev/tty.
+
 - Issue #8433: Fix test_curses failure with newer versions of ncurses.
 
 - Issue #9496: Provide a test suite for the rlcompleter module.  Patch by