diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2017-02-09 16:09:03 +0100 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-02-09 16:09:03 +0100 |
commit | 2a1d833d5da7fa7a01a2eef183b0a208ed019427 (patch) | |
tree | 8da3ebb695ae55c69d0a58691403fb13d96a9476 /Lib/test/support/__init__.py | |
parent | c6180bb73c8c7c7f9d8ea9816487b710597b6fc1 (diff) | |
parent | bbd3587a29510bd5a318e0a19fc8570c0cd3b622 (diff) | |
download | cpython-2a1d833d5da7fa7a01a2eef183b0a208ed019427.tar.gz |
Merge issue #26355 fix from 3.6
Diffstat (limited to 'Lib/test/support/__init__.py')
-rw-r--r-- | Lib/test/support/__init__.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 15d8fc849b..6658ece735 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -777,8 +777,13 @@ requires_lzma = unittest.skipUnless(lzma, 'requires lzma') is_jython = sys.platform.startswith('java') -_ANDROID_API_LEVEL = sysconfig.get_config_var('ANDROID_API_LEVEL') -is_android = (_ANDROID_API_LEVEL is not None and _ANDROID_API_LEVEL > 0) +try: + # constant used by requires_android_level() + _ANDROID_API_LEVEL = sys.getandroidapilevel() + is_android = True +except AttributeError: + # sys.getandroidapilevel() is only available on Android + is_android = False android_not_root = (is_android and os.geteuid() != 0) if sys.platform != 'win32': @@ -949,10 +954,11 @@ def temp_dir(path=None, quiet=False): try: os.mkdir(path) dir_created = True - except OSError: + except OSError as exc: if not quiet: raise - warnings.warn('tests may fail, unable to create temp dir: ' + path, + warnings.warn(f'tests may fail, unable to create ' + f'temporary directory {path!r}: {exc}', RuntimeWarning, stacklevel=3) try: yield path @@ -976,10 +982,11 @@ def change_cwd(path, quiet=False): saved_dir = os.getcwd() try: os.chdir(path) - except OSError: + except OSError as exc: if not quiet: raise - warnings.warn('tests may fail, unable to change CWD to: ' + path, + warnings.warn(f'tests may fail, unable to change the current working ' + f'directory to {path!r}: {exc}', RuntimeWarning, stacklevel=3) try: yield os.getcwd() |