@@ -433,16 +433,16 @@ mod test {
433433 where
434434 T : de:: DeserializeOwned + PartialEq + std:: fmt:: Debug ,
435435 {
436- let gil = Python :: acquire_gil ( ) ;
437- let py = gil . python ( ) ;
438- let locals = PyDict :: new ( py ) ;
439- py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
440- . unwrap ( ) ;
441- let obj = locals . get_item ( " obj" ) . unwrap ( ) ;
442- let actual : T = depythonize ( obj ) . unwrap ( ) ;
443- assert_eq ! ( & actual , expected ) ;
444- let actual_json : JsonValue = depythonize ( obj ) . unwrap ( ) ;
445- assert_eq ! ( & actual_json , expected_json ) ;
436+ Python :: with_gil ( |py| {
437+ let locals = PyDict :: new ( py ) ;
438+ py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
439+ . unwrap ( ) ;
440+ let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
441+ let actual : T = depythonize ( obj) . unwrap ( ) ;
442+ assert_eq ! ( & actual , expected ) ;
443+ let actual_json : JsonValue = depythonize ( obj ) . unwrap ( ) ;
444+ assert_eq ! ( & actual_json , expected_json ) ;
445+ } ) ;
446446 }
447447
448448 #[ test]
@@ -489,16 +489,16 @@ mod test {
489489
490490 let code = "{'foo': 'Foo'}" ;
491491
492- let gil = Python :: acquire_gil ( ) ;
493- let py = gil . python ( ) ;
494- let locals = PyDict :: new ( py ) ;
495- py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
496- . unwrap ( ) ;
497- let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
498- assert ! ( matches! (
499- * depythonize :: < Struct > ( obj ) . unwrap_err ( ) . inner ,
500- ErrorImpl :: Message ( msg ) if msg == "missing field `bar`"
501- ) ) ;
492+ Python :: with_gil ( |py| {
493+ let locals = PyDict :: new ( py ) ;
494+ py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
495+ . unwrap ( ) ;
496+ let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
497+ assert ! ( matches! (
498+ * depythonize :: < Struct > ( obj ) . unwrap_err ( ) . inner ,
499+ ErrorImpl :: Message ( msg ) if msg == "missing field `bar`"
500+ ) ) ;
501+ } )
502502 }
503503
504504 #[ test]
@@ -519,16 +519,16 @@ mod test {
519519
520520 let code = "('cat', -10.05, 'foo')" ;
521521
522- let gil = Python :: acquire_gil ( ) ;
523- let py = gil . python ( ) ;
524- let locals = PyDict :: new ( py ) ;
525- py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
526- . unwrap ( ) ;
527- let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
528- assert ! ( matches! (
529- * depythonize :: < TupleStruct > ( obj ) . unwrap_err ( ) . inner ,
530- ErrorImpl :: IncorrectSequenceLength { expected , got } if expected == 2 && got == 3
531- ) ) ;
522+ Python :: with_gil ( |py| {
523+ let locals = PyDict :: new ( py ) ;
524+ py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
525+ . unwrap ( ) ;
526+ let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
527+ assert ! ( matches! (
528+ * depythonize :: < TupleStruct > ( obj ) . unwrap_err ( ) . inner ,
529+ ErrorImpl :: IncorrectSequenceLength { expected , got } if expected == 2 && got == 3
530+ ) ) ;
531+ } )
532532 }
533533
534534 #[ test]
0 commit comments