diff options
author | Gregory P. Smith <greg@krypto.org> | 2022-02-03 05:36:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-03 05:36:16 (GMT) |
commit | 8726067ace98a27557e9fdf1a8e1c509c37cfcfc (patch) | |
tree | 374cf5fbe238721cfb66c2824575fd505ed2818c /Lib/test/support | |
parent | 51a95be1d035a717ab29e98056b8831a98e61125 (diff) | |
download | cpython-8726067ace98a27557e9fdf1a8e1c509c37cfcfc.zip cpython-8726067ace98a27557e9fdf1a8e1c509c37cfcfc.tar.gz cpython-8726067ace98a27557e9fdf1a8e1c509c37cfcfc.tar.bz2 |
bpo-45629: Improve test.support.skip_if_buildbot (GH-31094)
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.
Diffstat (limited to 'Lib/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index d71cfe5..e5eb66e 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -5,6 +5,7 @@ if __name__ != 'test.support': import contextlib import functools +import getpass import os import re import stat @@ -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): |