diff --git a/rust-runtime/aws-smithy-http-server-python/src/context/testing.rs b/rust-runtime/aws-smithy-http-server-python/src/context/testing.rs index f95f3aeda3e..31fbd3d8ee1 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/context/testing.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/context/testing.rs @@ -8,7 +8,7 @@ use http::{HeaderMap, HeaderValue}; use lambda_http::Context; use pyo3::{ - types::{IntoPyDict, PyDict}, + types::{PyDict, PyModule}, IntoPy, PyErr, Python, }; @@ -16,7 +16,8 @@ use super::{PyContext, PyLambdaContext}; pub fn get_context(code: &str) -> PyContext { let inner = Python::with_gil(|py| { - let globals = [("LambdaContext", py.get_type::())].into_py_dict(py); + let globals = PyModule::import(py, "__main__")?.dict(); + globals.set_item("LambdaContext", py.get_type::())?; let locals = PyDict::new(py); py.run(code, Some(globals), Some(locals))?; let context = locals