Skip to content

Commit

Permalink
bpo-45629: Improve test.support.skip_if_buildbot (GH-31094)
Browse files Browse the repository at this point in the history
It was added as part of #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.
  • Loading branch information
gpshead authored Feb 3, 2022
1 parent 51a95be commit 8726067
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import contextlib
import functools
import getpass
import os
import re
import stat
Expand Down Expand Up @@ -378,10 +379,11 @@ def skip_if_buildbot(reason=None):
"""Decorator raising SkipTest if running on a buildbot."""
if not reason:
reason = 'not suitable for buildbots'
if sys.platform == 'win32':
isbuildbot = os.environ.get('USERNAME') == 'Buildbot'
else:
isbuildbot = os.environ.get('USER') == 'buildbot'
try:
isbuildbot = getpass.getuser().lower() == 'buildbot'
except (KeyError, EnvironmentError) as err:
warnings.warn(f'getpass.getuser() failed {err}.', RuntimeWarning)
isbuildbot = False
return unittest.skipIf(isbuildbot, reason)

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

0 comments on commit 8726067

Please sign in to comment.