@@ -39,6 +39,12 @@ def setUp(self):
3939 # doesn't crash on some buildbots (Alphas in particular).
4040 support .reap_children ()
4141
42+ def tearDown (self ):
43+ for inst in subprocess ._active :
44+ inst .wait ()
45+ subprocess ._cleanup ()
46+ self .assertFalse (subprocess ._active , "subprocess._active not empty" )
47+
4248 def assertStderrEqual (self , stderr , expected , msg = None ):
4349 # In a debug build, stuff like "[6580 refs]" is printed to stderr at
4450 # shutdown time. That frustrates tests trying to check stderr produced
@@ -548,13 +554,19 @@ def __exit__(self, *args):
548554 pass
549555
550556
551- @unittest .skipIf (sys . platform == "win32" , "POSIX specific tests" )
557+ @unittest .skipIf (mswindows , "POSIX specific tests" )
552558class POSIXProcessTestCase (unittest .TestCase ):
553559 def setUp (self ):
554560 # Try to minimize the number of children we have so this test
555561 # doesn't crash on some buildbots (Alphas in particular).
556562 support .reap_children ()
557563
564+ def tearDown (self ):
565+ for inst in subprocess ._active :
566+ inst .wait ()
567+ subprocess ._cleanup ()
568+ self .assertFalse (subprocess ._active , "subprocess._active not empty" )
569+
558570 def test_exceptions (self ):
559571 # caught & re-raised exceptions
560572 with self .assertRaises (OSError ) as c :
@@ -636,23 +648,22 @@ def test_call_string(self):
636648 os .remove (fname )
637649 self .assertEqual (rc , 47 )
638650
639- @unittest .skip ("See issue #2777" )
640651 def test_send_signal (self ):
641652 p = subprocess .Popen ([sys .executable , "-c" , "input()" ])
642653
654+ # Let the process initialize correctly (Issue #3137)
655+ time .sleep (.1 )
643656 self .assertIs (p .poll (), None )
644657 p .send_signal (signal .SIGINT )
645- self .assertIsNot (p .wait (), None )
658+ self .assertNotEqual (p .wait (), 0 )
646659
647- @unittest .skip ("See issue #2777" )
648660 def test_kill (self ):
649661 p = subprocess .Popen ([sys .executable , "-c" , "input()" ])
650662
651663 self .assertIs (p .poll (), None )
652664 p .kill ()
653665 self .assertEqual (p .wait (), - signal .SIGKILL )
654666
655- @unittest .skip ("See issue #2777" )
656667 def test_terminate (self ):
657668 p = subprocess .Popen ([sys .executable , "-c" , "input()" ])
658669
@@ -661,13 +672,19 @@ def test_terminate(self):
661672 self .assertEqual (p .wait (), - signal .SIGTERM )
662673
663674
664- @unittest .skipUnless (sys . platform == "win32" , "Windows specific tests" )
675+ @unittest .skipUnless (mswindows , "Windows specific tests" )
665676class Win32ProcessTestCase (unittest .TestCase ):
666677 def setUp (self ):
667678 # Try to minimize the number of children we have so this test
668679 # doesn't crash on some buildbots (Alphas in particular).
669680 support .reap_children ()
670681
682+ def tearDown (self ):
683+ for inst in subprocess ._active :
684+ inst .wait ()
685+ subprocess ._cleanup ()
686+ self .assertFalse (subprocess ._active , "subprocess._active not empty" )
687+
671688 def test_startupinfo (self ):
672689 # startupinfo argument
673690 # We uses hardcoded constants, because we do not want to
@@ -734,23 +751,20 @@ def test_call_string(self):
734751 ' -c "import sys; sys.exit(47)"' )
735752 self .assertEqual (rc , 47 )
736753
737- @unittest .skip ("See issue #2777" )
738754 def test_send_signal (self ):
739755 p = subprocess .Popen ([sys .executable , "-c" , "input()" ])
740756
741757 self .assertIs (p .poll (), None )
742758 p .send_signal (signal .SIGTERM )
743759 self .assertNotEqual (p .wait (), 0 )
744760
745- @unittest .skip ("See issue #2777" )
746761 def test_kill (self ):
747762 p = subprocess .Popen ([sys .executable , "-c" , "input()" ])
748763
749764 self .assertIs (p .poll (), None )
750765 p .kill ()
751766 self .assertNotEqual (p .wait (), 0 )
752767
753- @unittest .skip ("See issue #2777" )
754768 def test_terminate (self ):
755769 p = subprocess .Popen ([sys .executable , "-c" , "input()" ])
756770
@@ -764,7 +778,7 @@ def test_terminate(self):
764778#
765779# Actually, getoutput should work on any platform with an os.popen, but
766780# I'll take the comment as given, and skip this suite.
767- @unittest .skipUnless (os .name ! = 'posix' , "only relevant for UNIX" )
781+ @unittest .skipUnless (os .name = = 'posix' , "only relevant for UNIX" )
768782class CommandTests (unittest .TestCase ):
769783 def test_getoutput (self ):
770784 self .assertEqual (subprocess .getoutput ('echo xyzzy' ), 'xyzzy' )
0 commit comments