Skip to content

Commit 4e7e2dd

Browse files
authored
pythongh-139322: Reenable test_os.test_getlogin() (python#139498)
Fix also getlogin() errno.
1 parent fb114cf commit 4e7e2dd

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Lib/test/test_os/test_os.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,13 +3197,16 @@ def test_spawnvpe_invalid_env(self):
31973197
self._test_invalid_env(os.spawnvpe)
31983198

31993199

3200-
# The introduction of this TestCase caused at least two different errors on
3201-
# *nix buildbots. Temporarily skip this to let the buildbots move along.
3202-
@unittest.skip("Skip due to platform/environment differences on *NIX buildbots")
32033200
@unittest.skipUnless(hasattr(os, 'getlogin'), "test needs os.getlogin")
32043201
class LoginTests(unittest.TestCase):
32053202
def test_getlogin(self):
3206-
user_name = os.getlogin()
3203+
try:
3204+
user_name = os.getlogin()
3205+
except OSError as exc:
3206+
if exc.errno in (errno.ENOTTY, errno.ENXIO):
3207+
self.skipTest(str(exc))
3208+
else:
3209+
raise
32073210
self.assertNotEqual(len(user_name), 0)
32083211

32093212

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`os.getlogin` error handling: fix the error number. Patch by
2+
Victor Stinner.

Modules/posixmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9605,7 +9605,7 @@ os_getlogin_impl(PyObject *module)
96059605
int err = getlogin_r(name, sizeof(name));
96069606
if (err) {
96079607
int old_errno = errno;
9608-
errno = -err;
9608+
errno = err;
96099609
posix_error();
96109610
errno = old_errno;
96119611
}

0 commit comments

Comments
 (0)