From 8c38bd5286fe37a759705b3088acaf4324a97b57 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Tue, 15 Aug 2023 17:29:40 -0700 Subject: [PATCH] gh-91051: fix type watcher test to be robust to existing watcher --- Lib/test/test_capi/test_watchers.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_capi/test_watchers.py b/Lib/test/test_capi/test_watchers.py index 10b76e163bfb21..236f439cc20923 100644 --- a/Lib/test/test_capi/test_watchers.py +++ b/Lib/test/test_capi/test_watchers.py @@ -351,12 +351,10 @@ def test_clear_unassigned_watcher_id(self): self.clear_watcher(1) def test_no_more_ids_available(self): - contexts = [self.watcher() for i in range(self.TYPE_MAX_WATCHERS)] - with ExitStack() as stack: - for ctx in contexts: - stack.enter_context(ctx) - with self.assertRaisesRegex(RuntimeError, r"no more type watcher IDs"): - self.add_watcher() + with self.assertRaisesRegex(RuntimeError, r"no more type watcher IDs"): + with ExitStack() as stack: + while True: + stack.enter_context(self.watcher()) class TestCodeObjectWatchers(unittest.TestCase):