]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103780: Use patch instead of mock in asyncio unix events test (#103782)
authorItamar Ostricher <itamarost@gmail.com>
Mon, 24 Apr 2023 20:12:48 +0000 (13:12 -0700)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2023 20:12:48 +0000 (20:12 +0000)
Lib/test/test_asyncio/test_unix_events.py

index 96999470a7c69a6c674160502fcb29e365dbddd9..cdf3eaac68af15983d86662376f7d9871f145c82 100644 (file)
@@ -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)
@@ -1725,10 +1725,9 @@ class PolicyTests(unittest.TestCase):
         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)