Skip to content

Commit

Permalink
Make sure to include Python builtins in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
unexge committed Nov 15, 2022
1 parent f55918d commit 55713da
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
use http::{HeaderMap, HeaderValue};
use lambda_http::Context;
use pyo3::{
types::{IntoPyDict, PyDict},
types::{PyDict, PyModule},
IntoPy, PyErr, Python,
};

use super::{PyContext, PyLambdaContext};

pub fn get_context(code: &str) -> PyContext {
let inner = Python::with_gil(|py| {
let globals = [("LambdaContext", py.get_type::<PyLambdaContext>())].into_py_dict(py);
let globals = PyModule::import(py, "__main__")?.dict();
globals.set_item("LambdaContext", py.get_type::<PyLambdaContext>())?;
let locals = PyDict::new(py);
py.run(code, Some(globals), Some(locals))?;
let context = locals
Expand Down

0 comments on commit 55713da

Please sign in to comment.