Skip to content

Commit

Permalink
gh-103780: Use patch instead of mock in asyncio unix events test (#10…
Browse files Browse the repository at this point in the history
  • Loading branch information
itamaro authored Apr 24, 2023
1 parent 04ea048 commit 518050c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Lib/test/test_asyncio/test_unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,11 +1712,11 @@ class PolicyTests(unittest.TestCase):
def create_policy(self):
return asyncio.DefaultEventLoopPolicy()

def test_get_default_child_watcher(self):
@mock.patch('asyncio.unix_events.can_use_pidfd')
def test_get_default_child_watcher(self, m_can_use_pidfd):
m_can_use_pidfd.return_value = False
policy = self.create_policy()
self.assertIsNone(policy._watcher)
unix_events.can_use_pidfd = mock.Mock()
unix_events.can_use_pidfd.return_value = False
with self.assertWarns(DeprecationWarning):
watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.ThreadedChildWatcher)
Expand All @@ -1725,10 +1725,9 @@ def test_get_default_child_watcher(self):
with self.assertWarns(DeprecationWarning):
self.assertIs(watcher, policy.get_child_watcher())

m_can_use_pidfd.return_value = True
policy = self.create_policy()
self.assertIsNone(policy._watcher)
unix_events.can_use_pidfd = mock.Mock()
unix_events.can_use_pidfd.return_value = True
with self.assertWarns(DeprecationWarning):
watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.PidfdChildWatcher)
Expand Down

0 comments on commit 518050c

Please sign in to comment.