def test_exec_with_locals(): loc = {} glob = {} exec("a = 1", glob, loc) assert loc assert glob assert loc['a'] == 1
def test_compile(): code = compile('x = raiz(0 ou 1)', '<string>', 'exec') D = {} exec(code, D, forbidden=False) assert D['x'] == 1 D = {} exec(code, D, forbidden=False) assert D['x'] == 1
def test_bad_syntax_raises_syntax_error(bad_syntax): with pytest.raises(SyntaxError): exec(bad_syntax)
def test_exec(): D = {} exec('x = raiz(0 ou 1) ', D, forbidden=False) assert D['x'] == 1