Fix SF bug #690081, test_posix fails when run in non-interactive mode
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 23 Feb 2003 22:12:24 +0000 (22:12 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 23 Feb 2003 22:12:24 +0000 (22:12 +0000)
Don't bother testing os.getlogin() if we aren't running from a tty (terminal)
It fails when run without a tty (e.g., when run from cron).

Lib/test/test_posix.py

index 4f0d5be4aaa01f0daf03de48c1f6ac8b9d3f5455..feb033d54db531d9542fd42d7588a4f859e0e201 100644 (file)
@@ -29,10 +29,17 @@ class PosixTester(unittest.TestCase):
         # test posix functions which take no arguments and have
         # no side-effects which we need to cleanup (e.g., fork, wait, abort)
         NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdu", "uname",
-                             "times", "getlogin", "getloadavg", "tmpnam",
+                             "times", "getloadavg", "tmpnam",
                              "getegid", "geteuid", "getgid", "getgroups",
                              "getpid", "getpgrp", "getppid", "getuid",
                            ]
+        # getlogin() only works when run from a tty (terminal)
+        try:
+            if os.isatty(sys.stdin.fileno()):
+                NO_ARG_FUNCTIONS.append("getlogin")
+        except:
+            pass
+
         for name in NO_ARG_FUNCTIONS:
             posix_func = getattr(posix, name, None)
             if posix_func is not None: