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
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")
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).