From 6fc2084e3cc9fc1e87967dc79f45a85c2861295e Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Wed, 16 Sep 2026 07:48:10 +0000 Subject: [PATCH] [IMP] endpoint_route_handler: restore _init_modules even when a test raises 369de3f restores `registry._init_modules` after `_get_mocked_request`, but the restore happens after the `with MockRequest(...)` block without a `try/finally`. If the test body raises inside the mocked request, the exception propagates out of the generator and the restore line is never reached, so the process-wide registry is left with an empty module set again. That attribute is not rolled back with the test transaction, and `ir.http.routing_map()` builds the routing map from exactly that set: installed = registry._init_modules.union(config["server_wide_modules"]) so the next routing-map regeneration yields no module controllers at all and every later `HttpCase` in the same process gets a 404 for any route outside `base` - the very failure 369de3f set out to fix, just on the error path. Wrap the `yield` in `try/finally` so the restore always runs. Assisted-by: Claude Opus 5 --- endpoint_route_handler/tests/common.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/endpoint_route_handler/tests/common.py b/endpoint_route_handler/tests/common.py index c2da51b9..cf511c18 100644 --- a/endpoint_route_handler/tests/common.py +++ b/endpoint_route_handler/tests/common.py @@ -52,8 +52,11 @@ def _get_mocked_request( setattr(mocked_request, k, v) mocked_request.make_response = lambda data, **kw: data mocked_request.registry._init_modules = set() - yield mocked_request - # Restore the real _init_modules. - # Without this, routing_map() keeps being built with an empty module - # set and post_install HttpCase tests in other modules get 404s. - registry._init_modules = original_init_modules + try: + yield mocked_request + finally: + # Restore the real _init_modules. + # Without this, routing_map() keeps being built with an empty + # module set and post_install HttpCase tests in other modules + # get 404s. + registry._init_modules = original_init_modules