Skip to content

Commit 897a36b

Browse files
yihong0618picnixz
andauthored
gh-139935: fix test_os.test_getlogin on some platforms (#139936)
This amends 4e7e2dd to catch errors that `os.getlogin` can raise as specified by POSIX and Linux/glibc [1]. [1]: https://man7.org/linux/man-pages/man3/getlogin.3.html#ERRORS --------- Signed-off-by: yihong0618 <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
1 parent d4e5802 commit 897a36b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Lib/test/test_os/test_os.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,14 @@ def test_getlogin(self):
32033203
try:
32043204
user_name = os.getlogin()
32053205
except OSError as exc:
3206-
if exc.errno in (errno.ENOTTY, errno.ENXIO):
3206+
# See https://man7.org/linux/man-pages/man3/getlogin.3.html#ERRORS.
3207+
allowed_errors = (
3208+
# defined by POSIX
3209+
errno.EMFILE, errno.ENFILE, errno.ENXIO, errno.ERANGE,
3210+
# defined by Linux/glibc
3211+
errno.ENOENT, errno.ENOMEM, errno.ENOTTY,
3212+
)
3213+
if exc.errno in allowed_errors:
32073214
self.skipTest(str(exc))
32083215
else:
32093216
raise

0 commit comments

Comments
 (0)