https://github.com/python/cpython/commit/4e7e2dd043c1da85b0c157d3ed24866b77e83a4f
commit: 4e7e2dd043c1da85b0c157d3ed24866b77e83a4f
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-10-02T20:51:57Z
summary:
gh-139322: Reenable test_os.test_getlogin() (#139498)
Fix also getlogin() errno.
files:
A Misc/NEWS.d/next/Library/2025-10-02-15-45-08.gh-issue-139322.rouPGj.rst
M Lib/test/test_os/test_os.py
M Modules/posixmodule.c
diff --git a/Lib/test/test_os/test_os.py b/Lib/test/test_os/test_os.py
index 43f1a79a7c7328..371771087aaf88 100644
--- a/Lib/test/test_os/test_os.py
+++ b/Lib/test/test_os/test_os.py
@@ -3197,13 +3197,16 @@ def test_spawnvpe_invalid_env(self):
self._test_invalid_env(os.spawnvpe)
-# The introduction of this TestCase caused at least two different errors on
-# *nix buildbots. Temporarily skip this to let the buildbots move along.
[email protected]("Skip due to platform/environment differences on *NIX
buildbots")
@unittest.skipUnless(hasattr(os, 'getlogin'), "test needs os.getlogin")
class LoginTests(unittest.TestCase):
def test_getlogin(self):
- user_name = os.getlogin()
+ try:
+ user_name = os.getlogin()
+ except OSError as exc:
+ if exc.errno in (errno.ENOTTY, errno.ENXIO):
+ self.skipTest(str(exc))
+ else:
+ raise
self.assertNotEqual(len(user_name), 0)
diff --git
a/Misc/NEWS.d/next/Library/2025-10-02-15-45-08.gh-issue-139322.rouPGj.rst
b/Misc/NEWS.d/next/Library/2025-10-02-15-45-08.gh-issue-139322.rouPGj.rst
new file mode 100644
index 00000000000000..39cae22474c4db
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-10-02-15-45-08.gh-issue-139322.rouPGj.rst
@@ -0,0 +1,2 @@
+Fix :func:`os.getlogin` error handling: fix the error number. Patch by
+Victor Stinner.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index b7a0110226590e..f50167c223e2fc 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -9605,7 +9605,7 @@ os_getlogin_impl(PyObject *module)
int err = getlogin_r(name, sizeof(name));
if (err) {
int old_errno = errno;
- errno = -err;
+ errno = err;
posix_error();
errno = old_errno;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]