summaryrefslogtreecommitdiffstats
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-05-23 09:22:44 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-05-23 09:22:44 (GMT)
commite02ba1031fc1ae1ad095b34f6a07451fb789e23f (patch)
tree47831164539cb54d2d6a9b4ae8a8391e7ae0e0f8 /Lib/test/support.py
parente1f107e981398db77b17f9e5f99f6bdda93abcd3 (diff)
downloadcpython-e02ba1031fc1ae1ad095b34f6a07451fb789e23f.zip
cpython-e02ba1031fc1ae1ad095b34f6a07451fb789e23f.tar.gz
cpython-e02ba1031fc1ae1ad095b34f6a07451fb789e23f.tar.bz2
#14885: Make support.skip_unless_xattr check also tempfile
There is a rare edge case where the filesystem used by the tempfile functions (usually /tmp) doesn't support xattrs while the one used by TESTFN (the current directory, so likely to be below /home) does. This causes the xattr related test_shutil tests fail. skip_unless_xattr now checks both. I have also added skip_unless_xattr to __all__ where it has been missing.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index e43dbad..6749a511 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -24,6 +24,7 @@ import sysconfig
import fnmatch
import logging.handlers
import struct
+import tempfile
try:
import _thread, threading
@@ -51,23 +52,25 @@ except ImportError:
lzma = None
__all__ = [
- "Error", "TestFailed", "ResourceDenied", "import_module",
- "verbose", "use_resources", "max_memuse", "record_original_stdout",
+ "Error", "TestFailed", "ResourceDenied", "import_module", "verbose",
+ "use_resources", "max_memuse", "record_original_stdout",
"get_original_stdout", "unload", "unlink", "rmtree", "forget",
"is_resource_enabled", "requires", "requires_freebsd_version",
- "requires_linux_version", "requires_mac_ver", "find_unused_port", "bind_port",
- "IPV6_ENABLED", "is_jython", "TESTFN", "HOST", "SAVEDCWD", "temp_cwd",
- "findfile", "create_empty_file", "sortdict", "check_syntax_error", "open_urlresource",
- "check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource",
- "captured_stdout", "captured_stdin", "captured_stderr", "time_out",
- "socket_peer_reset", "ioerror_peer_reset", "run_with_locale", 'temp_umask',
+ "requires_linux_version", "requires_mac_ver", "find_unused_port",
+ "bind_port", "IPV6_ENABLED", "is_jython", "TESTFN", "HOST", "SAVEDCWD",
+ "temp_cwd", "findfile", "create_empty_file", "sortdict",
+ "check_syntax_error", "open_urlresource", "check_warnings", "CleanImport",
+ "EnvironmentVarGuard", "TransientResource", "captured_stdout",
+ "captured_stdin", "captured_stderr", "time_out", "socket_peer_reset",
+ "ioerror_peer_reset", "run_with_locale", 'temp_umask',
"transient_internet", "set_memlimit", "bigmemtest", "bigaddrspacetest",
"BasicTestRunner", "run_unittest", "run_doctest", "threading_setup",
"threading_cleanup", "reap_children", "cpython_only", "check_impl_detail",
"get_attribute", "swap_item", "swap_attr", "requires_IEEE_754",
"TestHandler", "Matcher", "can_symlink", "skip_unless_symlink",
- "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE", "failfast",
- "anticipate_failure", "run_with_tz", "requires_bz2", "requires_lzma"
+ "skip_unless_xattr", "import_fresh_module", "requires_zlib",
+ "PIPE_MAX_SIZE", "failfast", "anticipate_failure", "run_with_tz",
+ "requires_bz2", "requires_lzma"
]
class Error(Exception):
@@ -1694,9 +1697,13 @@ def can_xattr():
if not hasattr(os, "setxattr"):
can = False
else:
+ tmp_fp, tmp_name = tempfile.mkstemp()
try:
with open(TESTFN, "wb") as fp:
try:
+ # TESTFN & tempfile may use different file systems with
+ # different capabilities
+ os.fsetxattr(tmp_fp, b"user.test", b"")
os.fsetxattr(fp.fileno(), b"user.test", b"")
# Kernels < 2.6.39 don't respect setxattr flags.
kernel_version = platform.release()
@@ -1706,6 +1713,7 @@ def can_xattr():
can = False
finally:
unlink(TESTFN)
+ unlink(tmp_name)
_can_xattr = can
return can