Skip to content

Commit f0c66f9

Browse files
committed
bpo-45629: Improve test.support.skip_if_buildbot
It was added as part of python#29222 to avoid running freeze tool tests on the buildbots but the logic was wrong so it did not skip tests on typical posix setup buildbots where the worker is launched from cron via an @reboot task and thus have no USER environment variable. This uses the canonical `getpass.getuser()` API rather than rolling its own attempt.
1 parent 164a017 commit f0c66f9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Lib/test/support/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import contextlib
77
import functools
8+
import getpass
89
import os
910
import re
1011
import stat
@@ -378,10 +379,11 @@ def skip_if_buildbot(reason=None):
378379
"""Decorator raising SkipTest if running on a buildbot."""
379380
if not reason:
380381
reason = 'not suitable for buildbots'
381-
if sys.platform == 'win32':
382-
isbuildbot = os.environ.get('USERNAME') == 'Buildbot'
383-
else:
384-
isbuildbot = os.environ.get('USER') == 'buildbot'
382+
try:
383+
isbuildbot = getpass.getuser().lower() == 'buildbot'
384+
except (KeyError, EnvironmentError) as err:
385+
warnings.warn(f'getpass.getuser() failed {err}.', RuntimeWarning)
386+
isbuildbot = False
385387
return unittest.skipIf(isbuildbot, reason)
386388

387389
def check_sanitizer(*, address=False, memory=False, ub=False):

0 commit comments

Comments
 (0)