Skip to content

Commit a76f2e2

Browse files
committed
pythongh-103780: Use patch instead of mock in asyncio unix events test
Fixes pythongh-103780
1 parent dca27a6 commit a76f2e2

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Lib/test/test_asyncio/test_unix_events.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -1713,29 +1713,29 @@ def create_policy(self):
17131713
return asyncio.DefaultEventLoopPolicy()
17141714

17151715
def test_get_default_child_watcher(self):
1716-
policy = self.create_policy()
1717-
self.assertIsNone(policy._watcher)
1718-
unix_events.can_use_pidfd = mock.Mock()
1719-
unix_events.can_use_pidfd.return_value = False
1720-
with self.assertWarns(DeprecationWarning):
1721-
watcher = policy.get_child_watcher()
1722-
self.assertIsInstance(watcher, asyncio.ThreadedChildWatcher)
1716+
with mock.patch('asyncio.unix_events.can_use_pidfd',
1717+
return_value=False):
1718+
policy = self.create_policy()
1719+
self.assertIsNone(policy._watcher)
1720+
with self.assertWarns(DeprecationWarning):
1721+
watcher = policy.get_child_watcher()
1722+
self.assertIsInstance(watcher, asyncio.ThreadedChildWatcher)
17231723

1724-
self.assertIs(policy._watcher, watcher)
1725-
with self.assertWarns(DeprecationWarning):
1726-
self.assertIs(watcher, policy.get_child_watcher())
1724+
self.assertIs(policy._watcher, watcher)
1725+
with self.assertWarns(DeprecationWarning):
1726+
self.assertIs(watcher, policy.get_child_watcher())
17271727

1728-
policy = self.create_policy()
1729-
self.assertIsNone(policy._watcher)
1730-
unix_events.can_use_pidfd = mock.Mock()
1731-
unix_events.can_use_pidfd.return_value = True
1732-
with self.assertWarns(DeprecationWarning):
1733-
watcher = policy.get_child_watcher()
1734-
self.assertIsInstance(watcher, asyncio.PidfdChildWatcher)
1728+
with mock.patch('asyncio.unix_events.can_use_pidfd',
1729+
return_value=True):
1730+
policy = self.create_policy()
1731+
self.assertIsNone(policy._watcher)
1732+
with self.assertWarns(DeprecationWarning):
1733+
watcher = policy.get_child_watcher()
1734+
self.assertIsInstance(watcher, asyncio.PidfdChildWatcher)
17351735

1736-
self.assertIs(policy._watcher, watcher)
1737-
with self.assertWarns(DeprecationWarning):
1738-
self.assertIs(watcher, policy.get_child_watcher())
1736+
self.assertIs(policy._watcher, watcher)
1737+
with self.assertWarns(DeprecationWarning):
1738+
self.assertIs(watcher, policy.get_child_watcher())
17391739

17401740
def test_get_child_watcher_after_set(self):
17411741
policy = self.create_policy()

0 commit comments

Comments
 (0)