diff options
author | Matthias Braun <matze@braunis.de> | 2020-03-17 09:51:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-17 09:51:44 -0700 |
commit | 52268941f37e3e27bd01792b081877ec3bc9ce12 (patch) | |
tree | b690475b9a1443d3a33ad551ef6851ba60346fd8 /Lib/test/test_shutil.py | |
parent | 982307b9cceef36e30ac43b13032d68c3b921adc (diff) | |
download | cpython-git-52268941f37e3e27bd01792b081877ec3bc9ce12.tar.gz |
bpo-26067: Do not fail test_shutil / chown when gid/uid cannot be resolved (#19032)
* bpo-26067: Do not fail test_shutil.chown when gid/uid cannot be resolved
There is no guarantee that the users primary uid or gid can be resolved
in the unix group/account databases. Skip the last part of the chown
test if we cannot resolve the gid or uid to a name.
* 📜🤖 Added by blurb_it.
* Address review feedback
* address review feedback correctly
* fix typo
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r-- | Lib/test/test_shutil.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 076c450e09..b9fdfd1350 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1666,12 +1666,17 @@ class TestMisc(BaseTest, unittest.TestCase): shutil.chown(dirname, group=gid) check_chown(dirname, gid=gid) - user = pwd.getpwuid(uid)[0] - group = grp.getgrgid(gid)[0] - shutil.chown(filename, user, group) - check_chown(filename, uid, gid) - shutil.chown(dirname, user, group) - check_chown(dirname, uid, gid) + try: + user = pwd.getpwuid(uid)[0] + group = grp.getgrgid(gid)[0] + except KeyError: + # On some systems uid/gid cannot be resolved. + pass + else: + shutil.chown(filename, user, group) + check_chown(filename, uid, gid) + shutil.chown(dirname, user, group) + check_chown(dirname, uid, gid) class TestWhich(BaseTest, unittest.TestCase): |