@@ -699,34 +699,40 @@ class SubprocessPidfdWatcherTests(SubprocessWatcherMixin,
699699 test_utils .TestCase ):
700700 Watcher = unix_events .PidfdChildWatcher
701701
702- else :
703- # Windows
704- class SubprocessProactorTests (SubprocessMixin , test_utils .TestCase ):
705-
706- def setUp (self ):
707- super ().setUp ()
708- self .loop = asyncio .ProactorEventLoop ()
709- self .set_event_loop (self .loop )
710702
703+ class GenericWatcherTests (test_utils .TestCase ):
711704
712- class GenericWatcherTests :
705+ def test_create_subprocess_fails_with_inactive_watcher (self ):
706+ watcher = mock .create_autospec (
707+ asyncio .AbstractChildWatcher ,
708+ ** {"__enter__.return_value.is_active.return_value" : False }
709+ )
713710
714- def test_create_subprocess_fails_with_inactive_watcher (self ):
711+ async def execute ():
712+ asyncio .set_child_watcher (watcher )
715713
716- async def execute ():
717- watcher = mock .create_authspec (asyncio .AbstractChildWatcher )
718- watcher .is_active .return_value = False
719- asyncio .set_child_watcher (watcher )
714+ with self .assertRaises (RuntimeError ):
715+ await subprocess .create_subprocess_exec (
716+ os_helper .FakePath (sys .executable ), '-c' , 'pass' )
720717
721- with self .assertRaises (RuntimeError ):
722- await subprocess .create_subprocess_exec (
723- os_helper .FakePath (sys .executable ), '-c' , 'pass' )
718+ watcher .add_child_handler .assert_not_called ()
724719
725- watcher .add_child_handler .assert_not_called ()
726-
727- self .assertIsNone (self .loop .run_until_complete (execute ()))
720+ with asyncio .Runner (loop_factory = asyncio .new_event_loop ) as runner :
721+ self .assertIsNone (runner .run (execute ()))
722+ self .assertListEqual (watcher .mock_calls , [
723+ mock .call .__enter__ (),
724+ mock .call .__enter__ ().is_active (),
725+ mock .call .__exit__ (RuntimeError , mock .ANY , mock .ANY ),
726+ ])
728727
728+ else :
729+ # Windows
730+ class SubprocessProactorTests (SubprocessMixin , test_utils .TestCase ):
729731
732+ def setUp (self ):
733+ super ().setUp ()
734+ self .loop = asyncio .ProactorEventLoop ()
735+ self .set_event_loop (self .loop )
730736
731737
732738if __name__ == '__main__' :
0 commit comments