mirror of https://github.com/python/cpython
#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.
This commit is contained in:
parent
e1f107e981
commit
e02ba1031f
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue