]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-139322: Reenable test_os.test_getlogin() (#139498)
authorVictor Stinner <vstinner@python.org>
Thu, 2 Oct 2025 20:51:57 +0000 (22:51 +0200)
committerGitHub <noreply@github.com>
Thu, 2 Oct 2025 20:51:57 +0000 (20:51 +0000)
Fix also getlogin() errno.

Lib/test/test_os/test_os.py
Misc/NEWS.d/next/Library/2025-10-02-15-45-08.gh-issue-139322.rouPGj.rst [new file with mode: 0644]
Modules/posixmodule.c

index 43f1a79a7c732894a080eec6244ff52357f55e81..371771087aaf88b1afc33a703f37226783d5891e 100644 (file)
@@ -3197,13 +3197,16 @@ class SpawnTests(unittest.TestCase):
         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.
-@unittest.skip("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 (file)
index 0000000..39cae22
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :func:`os.getlogin` error handling: fix the error number. Patch by
+Victor Stinner.
index b7a0110226590ea3947d42f011b874111265dab9..f50167c223e2fc4b75d6f51cdf66f18995a7086d 100644 (file)
@@ -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;
     }