Skip to content

Commit 3d4a3fd

Browse files
committed
don't fail everything if one context initialization fails in junit tests and interleave open contexts
1 parent 3109ef6 commit 3d4a3fd

File tree

1 file changed

+16
-6
lines changed
  • graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test

1 file changed

+16
-6
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/PythonTests.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,28 @@ public class PythonTests {
8484
public static void enterContext(String... newArgs) {
8585
PythonTests.outArray.reset();
8686
PythonTests.errArray.reset();
87-
if (context != null) {
88-
closeContext();
89-
}
87+
Context prevContext = context;
9088
context = Context.newBuilder().engine(engine).allowAllAccess(true).arguments("python", newArgs).build();
9189
context.initialize("python");
90+
if (prevContext != null) {
91+
closeContext(prevContext);
92+
}
9293
context.enter();
9394
}
9495

96+
private static void closeContext(Context ctxt) {
97+
try {
98+
ctxt.leave();
99+
} catch (RuntimeException e) {
100+
}
101+
ctxt.close();
102+
}
103+
95104
public static void closeContext() {
96-
context.leave();
97-
context.close();
98-
context = null;
105+
if (context != null) {
106+
closeContext(context);
107+
context = null;
108+
}
99109
}
100110

101111
public static void assertBenchNoError(Path scriptName, String[] args) {

0 commit comments

Comments
 (0)