[Python-checkins] bpo-41443: Add more attribute checking in test_posix (GH-21688)

vstinner webhook-mailer at python.org
Tue Dec 8 18:18:46 EST 2020


https://github.com/python/cpython/commit/eb7594f85741ef809b1ee337ee3431df20e6f8bb
commit: eb7594f85741ef809b1ee337ee3431df20e6f8bb
branch: master
author: pxinwr <peixing.xin at windriver.com>
committer: vstinner <vstinner at python.org>
date: 2020-12-09T00:18:37+01:00
summary:

bpo-41443:  Add more attribute checking in test_posix (GH-21688)

files:
A Misc/NEWS.d/next/Tests/2020-07-30-18-43-05.bpo-41443.834gyg.rst
M Lib/test/test_posix.py

diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index d4d348cdc02d0..185b293b07046 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -1094,7 +1094,8 @@ def test_chmod_dir_fd(self):
         finally:
             posix.close(f)
 
-    @unittest.skipUnless(os.chown in os.supports_dir_fd, "test needs dir_fd support in os.chown()")
+    @unittest.skipUnless(hasattr(os, 'chown') and (os.chown in os.supports_dir_fd),
+                         "test needs dir_fd support in os.chown()")
     def test_chown_dir_fd(self):
         os_helper.unlink(os_helper.TESTFN)
         os_helper.create_empty_file(os_helper.TESTFN)
@@ -1189,7 +1190,9 @@ def test_mkdir_dir_fd(self):
             posix.close(f)
             os_helper.rmtree(os_helper.TESTFN + 'dir')
 
-    @unittest.skipUnless((os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'),
+    @unittest.skipUnless(hasattr(os, 'mknod')
+                         and (os.mknod in os.supports_dir_fd)
+                         and hasattr(stat, 'S_IFIFO'),
                          "test requires both stat.S_IFIFO and dir_fd support for os.mknod()")
     def test_mknod_dir_fd(self):
         # Test using mknodat() to create a FIFO (the only use specified
@@ -1222,7 +1225,8 @@ def test_open_dir_fd(self):
             posix.close(a)
             posix.close(b)
 
-    @unittest.skipUnless(os.readlink in os.supports_dir_fd, "test needs dir_fd support in os.readlink()")
+    @unittest.skipUnless(hasattr(os, 'readlink') and (os.readlink in os.supports_dir_fd),
+                         "test needs dir_fd support in os.readlink()")
     def test_readlink_dir_fd(self):
         os.symlink(os_helper.TESTFN, os_helper.TESTFN + 'link')
         f = posix.open(posix.getcwd(), posix.O_RDONLY)
diff --git a/Misc/NEWS.d/next/Tests/2020-07-30-18-43-05.bpo-41443.834gyg.rst b/Misc/NEWS.d/next/Tests/2020-07-30-18-43-05.bpo-41443.834gyg.rst
new file mode 100644
index 0000000000000..439f3e3647015
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2020-07-30-18-43-05.bpo-41443.834gyg.rst
@@ -0,0 +1 @@
+Add more attribute checking in test_posix.py



More information about the Python-checkins mailing list