Skip to content

Commit d19b5d8

Browse files
gh-95010: Fix asyncio GenericWatcherTests.test_create_subprocess_fails_with_inactive_watcher (GH-95009)
The test was never run, because it was missing the TestCase class. The test failed because the wrong attribute was patched. (cherry picked from commit 834bd5d) Co-authored-by: Thomas Grainger <tagrain@gmail.com>
1 parent e2e8ec0 commit d19b5d8

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

Lib/test/test_asyncio/test_subprocess.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -700,34 +700,40 @@ class SubprocessPidfdWatcherTests(SubprocessWatcherMixin,
700700
test_utils.TestCase):
701701
Watcher = unix_events.PidfdChildWatcher
702702

703-
else:
704-
# Windows
705-
class SubprocessProactorTests(SubprocessMixin, test_utils.TestCase):
706-
707-
def setUp(self):
708-
super().setUp()
709-
self.loop = asyncio.ProactorEventLoop()
710-
self.set_event_loop(self.loop)
711703

704+
class GenericWatcherTests(test_utils.TestCase):
712705

713-
class GenericWatcherTests:
706+
def test_create_subprocess_fails_with_inactive_watcher(self):
707+
watcher = mock.create_autospec(
708+
asyncio.AbstractChildWatcher,
709+
**{"__enter__.return_value.is_active.return_value": False}
710+
)
714711

715-
def test_create_subprocess_fails_with_inactive_watcher(self):
712+
async def execute():
713+
asyncio.set_child_watcher(watcher)
716714

717-
async def execute():
718-
watcher = mock.create_authspec(asyncio.AbstractChildWatcher)
719-
watcher.is_active.return_value = False
720-
asyncio.set_child_watcher(watcher)
715+
with self.assertRaises(RuntimeError):
716+
await subprocess.create_subprocess_exec(
717+
os_helper.FakePath(sys.executable), '-c', 'pass')
721718

722-
with self.assertRaises(RuntimeError):
723-
await subprocess.create_subprocess_exec(
724-
os_helper.FakePath(sys.executable), '-c', 'pass')
719+
watcher.add_child_handler.assert_not_called()
725720

726-
watcher.add_child_handler.assert_not_called()
727-
728-
self.assertIsNone(self.loop.run_until_complete(execute()))
721+
with asyncio.Runner(loop_factory=asyncio.new_event_loop) as runner:
722+
self.assertIsNone(runner.run(execute()))
723+
self.assertListEqual(watcher.mock_calls, [
724+
mock.call.__enter__(),
725+
mock.call.__enter__().is_active(),
726+
mock.call.__exit__(RuntimeError, mock.ANY, mock.ANY),
727+
])
729728

729+
else:
730+
# Windows
731+
class SubprocessProactorTests(SubprocessMixin, test_utils.TestCase):
730732

733+
def setUp(self):
734+
super().setUp()
735+
self.loop = asyncio.ProactorEventLoop()
736+
self.set_event_loop(self.loop)
731737

732738

733739
if __name__ == '__main__':

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy