This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_shutil.TestWhich.test_non_matching_mode fails when running as root
Type: Stage: resolved
Components: Tests Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: doko, hynek, jibel, python-dev, serhiy.storchaka, tarek
Priority: normal Keywords: patch

Created on 2013-04-16 08:13 by jibel, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_shutil.log jibel, 2013-04-16 08:13
test_shutil_skip_test_non_matching_mode.patch serhiy.storchaka, 2013-05-26 06:55 review
Messages (5)
msg187054 - (view) Author: Jean-Baptiste Lallement (jibel) Date: 2013-04-16 08:13
The test test_shutil.TestWhich.test_non_matching_mode fails when running as root because the temporary file is always writeable for this user.

To reproduce on linux:
$ sudo python3.3 -E -Wd -tt /usr/lib/python3.3/test/regrtest.py -v -w test_shutil
[...]
======================================================================
FAIL: test_non_matching_mode (test.test_shutil.TestWhich)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.3/test/test_shutil.py", line 1334, in test_non_matching_mode
    self.assertIsNone(rv)
AssertionError: '/tmp/Tmpnf1xg5/Tmptzup_q.Exe' is not None

----------------------------------------------------------------------

Possible solutions:
- skip the test when running as root
- search for a file with executable bit set instead of writeable
- set immutable attribute on the file
msg187055 - (view) Author: Jean-Baptiste Lallement (jibel) Date: 2013-04-16 08:14
Reference on LP: https://bugs.launchpad.net/ubuntu/+source/python3.3/+bug/1169458
msg187064 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2013-04-16 10:23
one way would be to skip this test when running as root. Would the check for the X bit work on Windows?

    @unittest.skipUnless(hasattr(os, 'getuid') and os.getuid() != 0,
                         "test always succeeds as root")
msg190067 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-05-26 06:55
Here is a patch which skips test_non_matching_mode when run as root (for early skip in discovery stage and for more appropriate for this case report) and when run on OS or FS which doesn't support read-only files (should cover all other cases).
msg190203 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-05-28 12:56
New changeset b98380a1d979 by Serhiy Storchaka in branch '3.3':
Issue #17746: Skip test_shutil.test_non_matching_mode when run as root or
http://hg.python.org/cpython/rev/b98380a1d979

New changeset 96e543ba96a4 by Serhiy Storchaka in branch 'default':
Issue #17746: Skip test_shutil.test_non_matching_mode when run as root or
http://hg.python.org/cpython/rev/96e543ba96a4
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 61946
2013-05-28 13:13:16serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2013-05-28 12:56:32python-devsetnosy: + python-dev
messages: + msg190203
2013-05-26 07:13:35serhiy.storchakasetassignee: serhiy.storchaka
2013-05-26 06:55:50serhiy.storchakasetfiles: + test_shutil_skip_test_non_matching_mode.patch
messages: + msg190067

components: + Tests, - Library (Lib)
keywords: + patch
stage: needs patch -> patch review
2013-05-26 06:12:05serhiy.storchakalinkissue18061 dependencies
2013-04-16 10:39:57dokolinkissue17750 dependencies
2013-04-16 10:23:10dokosetnosy: + doko
messages: + msg187064
2013-04-16 09:19:35serhiy.storchakasetnosy: + tarek, hynek, serhiy.storchaka
stage: needs patch

components: + Library (Lib), - Tests
versions: + Python 3.4
2013-04-16 08:14:25jibelsetmessages: + msg187055
2013-04-16 08:13:18jibelcreate