@@ -1189,22 +1189,15 @@ def raise_it():
11891189 self .fail ("Exception raised by preexec_fn did not make it "
11901190 "to the parent process." )
11911191
1192- @unittest .skipIf (not os .path .exists ("/dev/zero" ), "/dev/zero required." )
1193- def test_preexec_errpipe_does_not_double_close_pipes (self ):
1194- """Issue16140: Don't double close pipes on preexec error."""
1195- class SafeConstructorPopen (subprocess .Popen ):
1196- def __init__ (self ):
1197- pass # Do nothing so we can modify the instance for testing.
1198- def RealPopen (self , * args , ** kwargs ):
1199- subprocess .Popen .__init__ (self , * args , ** kwargs )
1200- def raise_it ():
1201- raise RuntimeError ("force the _execute_child() errpipe_data path." )
1202-
1203- p = SafeConstructorPopen ()
1192+ class _TestExecuteChildPopen (subprocess .Popen ):
1193+ """Used to test behavior at the end of _execute_child."""
1194+ def __init__ (self , testcase , * args , ** kwargs ):
1195+ self ._testcase = testcase
1196+ subprocess .Popen .__init__ (self , * args , ** kwargs )
12041197
1205- def _test_fds_execute_child_wrapper ( * args , ** kwargs ):
1198+ def _execute_child ( self , * args , ** kwargs ):
12061199 try :
1207- subprocess .Popen ._execute_child (p , * args , ** kwargs )
1200+ subprocess .Popen ._execute_child (self , * args , ** kwargs )
12081201 finally :
12091202 # Open a bunch of file descriptors and verify that
12101203 # none of them are the same as the ones the Popen
@@ -1213,17 +1206,23 @@ def _test_fds_execute_child_wrapper(*args, **kwargs):
12131206 for _ in range (8 )]
12141207 try :
12151208 for fd in devzero_fds :
1216- self .assertNotIn ( fd , (
1217- p .stdin .fileno (), p .stdout .fileno (),
1218- p .stderr .fileno ()),
1209+ self ._testcase . assertNotIn (
1210+ fd , ( self .stdin .fileno (), self .stdout .fileno (),
1211+ self .stderr .fileno ()),
12191212 msg = "At least one fd was closed early." )
12201213 finally :
12211214 map (os .close , devzero_fds )
12221215
1223- p ._execute_child = _test_fds_execute_child_wrapper
1216+ @unittest .skipIf (not os .path .exists ("/dev/zero" ), "/dev/zero required." )
1217+ def test_preexec_errpipe_does_not_double_close_pipes (self ):
1218+ """Issue16140: Don't double close pipes on preexec error."""
1219+
1220+ def raise_it ():
1221+ raise RuntimeError ("force the _execute_child() errpipe_data path." )
12241222
12251223 with self .assertRaises (RuntimeError ):
1226- p .RealPopen ([sys .executable , "-c" , "pass" ],
1224+ self ._TestExecuteChildPopen (
1225+ self , [sys .executable , "-c" , "pass" ],
12271226 stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
12281227 stderr = subprocess .PIPE , preexec_fn = raise_it )
12291228
0 commit comments