@Test
public void testPythonExecutorReleasedAfterException() {

    final String script = "";
    final Map<String, Serializable> args = new HashMap<>();
    final PythonExecutor pythonExecutor = mock(PythonExecutor.class);
    when(pythonExecutor.exec(script, args)).thenThrow(new IllegalArgumentException(""));
    PythonExecutionCachedEngine engine = new PythonExecutionCachedEngine() {
        public PythonExecutor allocateExecutor(Set<String> dependencies) {
            return pythonExecutor;
        }
    };
    try {
        engine.exec(Collections.<String>emptySet(),script, args);
    } catch (Throwable t) {
        assertTrue(t instanceof IllegalArgumentException);
    }
    verify(pythonExecutor).release();
}