From 4e788743eb5fc0703dc3631c280772c8868b6c0e Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Mon, 14 Oct 2024 18:00:38 +0500 Subject: [PATCH] Fix exec() / locals() interaction, changed in 3.13. --- tests/test_injection.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_injection.py b/tests/test_injection.py index ba50861d..44ca6eb0 100644 --- a/tests/test_injection.py +++ b/tests/test_injection.py @@ -743,8 +743,9 @@ class TestInjectorStats: def test_stats(self, cb_args, expected, injector): def callback_factory(): args = ", ".join([f"{k}: {v.__name__}" for k, v in cb_args.items()]) - exec(f"def callback(response: DummyResponse, {args}): pass") - return locals().get("callback") + ns = {} + exec(f"def callback(response: DummyResponse, {args}): pass", None, ns) + return ns["callback"] callback = callback_factory() response = get_response_for_testing(callback)