@@ -1639,23 +1639,35 @@ def test_setsigmask_wrong_type(self):
16391639 os .environ , setsigmask = [signal .NSIG ,
16401640 signal .NSIG + 1 ])
16411641
1642- @unittest .skipIf (True ,
1643- "FIXME: bpo-35537: test fails is setsid is supported" )
1644- def test_start_new_session (self ):
1645- # For code coverage of calling setsid(). We don't care if we get an
1646- # EPERM error from it depending on the test execution environment, that
1647- # still indicates that it was called.
1648- code = "import os; print(os.getpgid(os.getpid()))"
1642+ def test_setsid (self ):
1643+ rfd , wfd = os .pipe ()
1644+ self .addCleanup (os .close , rfd )
16491645 try :
1650- self .spawn_func (sys .executable ,
1651- [sys .executable , "-c" , code ],
1652- os .environ , setsid = True )
1653- except NotImplementedError as exc :
1654- self .skipTest ("setsid is not supported: %s" % exc )
1655- else :
1656- parent_pgid = os .getpgid (os .getpid ())
1657- child_pgid = int (output )
1658- self .assertNotEqual (parent_pgid , child_pgid )
1646+ os .set_inheritable (wfd , True )
1647+
1648+ code = textwrap .dedent (f"""
1649+ import os
1650+ fd = { wfd }
1651+ sid = os.getsid(0)
1652+ os.write(fd, str(sid).encode())
1653+ """ )
1654+
1655+ try :
1656+ pid = self .spawn_func (sys .executable ,
1657+ [sys .executable , "-c" , code ],
1658+ os .environ , setsid = True )
1659+ except NotImplementedError as exc :
1660+ self .skipTest (f"setsid is not supported: { exc !r} " )
1661+ except PermissionError as exc :
1662+ self .skipTest (f"setsid failed with: { exc !r} " )
1663+ finally :
1664+ os .close (wfd )
1665+
1666+ self .assertEqual (os .waitpid (pid , 0 ), (pid , 0 ))
1667+ output = os .read (rfd , 100 )
1668+ child_sid = int (output )
1669+ parent_sid = os .getsid (os .getpid ())
1670+ self .assertNotEqual (parent_sid , child_sid )
16591671
16601672 @unittest .skipUnless (hasattr (signal , 'pthread_sigmask' ),
16611673 'need signal.pthread_sigmask()' )
0 commit comments