From ff87ad052d50cf09a50bb3501e0fc9f01072151b Mon Sep 17 00:00:00 2001 From: Dean Li Date: Mon, 7 Jun 2021 19:53:48 +0800 Subject: [PATCH] os: Fix openpty test Make openpty return non-inheritable file descriptors --- Lib/test/test_os.py | 2 -- vm/src/stdlib/os.rs | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 6151ac3172..85f124e752 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -3616,8 +3616,6 @@ class FDInheritanceTests(unittest.TestCase): self.assertEqual(os.dup2(fd, fd3, inheritable=False), fd3) self.assertFalse(os.get_inheritable(fd3)) - # TODO: RUSTPYTHON - @unittest.expectedFailure @unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()") def test_openpty(self): master_fd, slave_fd = os.openpty() diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index a5d0f84d69..9c54019f72 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -2371,6 +2371,9 @@ mod posix { #[pyfunction] fn openpty(vm: &VirtualMachine) -> PyResult { let r = nix::pty::openpty(None, None).map_err(|err| err.into_pyexception(vm))?; + for fd in &[r.master, r.slave] { + raw_set_inheritable(*fd, false).map_err(|e| e.into_pyexception(vm))?; + } Ok(vm .ctx .new_tuple(vec![vm.ctx.new_int(r.master), vm.ctx.new_int(r.slave)]))