]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91051: fix type watcher test to be robust to existing watcher (#107989)
authorCarl Meyer <carl@oddbird.net>
Wed, 16 Aug 2023 19:13:32 +0000 (13:13 -0600)
committerGitHub <noreply@github.com>
Wed, 16 Aug 2023 19:13:32 +0000 (13:13 -0600)
Lib/test/test_capi/test_watchers.py

index 10b76e163bfb216deaf3aee52aa69a3c85438eb6..6b8855ec219d274b054583d6e763ecb8953bbfe9 100644 (file)
@@ -351,12 +351,10 @@ class TestTypeWatchers(unittest.TestCase):
             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):