[Python-checkins] gh-91051: fix type watcher test to be robust to existing watcher (#107989)

carljm webhook-mailer at python.org
Wed Aug 16 15:13:36 EDT 2023


https://github.com/python/cpython/commit/fce93c80ae2d792b8ca443b044e28abbf28bb89a
commit: fce93c80ae2d792b8ca443b044e28abbf28bb89a
branch: main
author: Carl Meyer <carl at oddbird.net>
committer: carljm <carl at oddbird.net>
date: 2023-08-16T13:13:32-06:00
summary:

gh-91051: fix type watcher test to be robust to existing watcher (#107989)

files:
M Lib/test/test_capi/test_watchers.py

diff --git a/Lib/test/test_capi/test_watchers.py b/Lib/test/test_capi/test_watchers.py
index 10b76e163bfb2..6b8855ec219d2 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:
+                for _ in range(self.TYPE_MAX_WATCHERS + 1):
+                    stack.enter_context(self.watcher())
 
 
 class TestCodeObjectWatchers(unittest.TestCase):



More information about the Python-checkins mailing list