From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 16 Aug 2023 23:18:24 +0000 (-0700) Subject: [3.12] gh-91051: fix type watcher test to be robust to existing watcher (GH-107989... X-Git-Tag: v3.12.0rc2~145 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=84a4370e31632fb04590131ed24329c60cf2f356;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-91051: fix type watcher test to be robust to existing watcher (GH-107989) (#108053) gh-91051: fix type watcher test to be robust to existing watcher (GH-107989) (cherry picked from commit fce93c80ae2d792b8ca443b044e28abbf28bb89a) Co-authored-by: Carl Meyer --- diff --git a/Lib/test/test_capi/test_watchers.py b/Lib/test/test_capi/test_watchers.py index 10b76e163bfb..6b8855ec219d 100644 --- a/Lib/test/test_capi/test_watchers.py +++ b/Lib/test/test_capi/test_watchers.py @@ -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):