diff --git a/Lib/test/support.py b/Lib/test/support.py index e43dbad34de..6749a5115e0 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