Skip to content

Commit e02b1bf

Browse files
committed
Rethrow thread exception when executing tests
1 parent e757dd6 commit e02b1bf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

tests/IronPython.Tests/Cases/CaseExecuter.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Reflection;
1111
using System.Runtime.CompilerServices;
1212
using System.Runtime.InteropServices;
13+
using System.Runtime.ExceptionServices;
1314
using System.Text.RegularExpressions;
1415
using System.Threading;
1516

@@ -290,7 +291,9 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc
290291
engine.GetSysModule().SetVariable("argv", PythonList.FromArrayNoCopy(new object[] { source.Path }));
291292
var compiledCode = source.Compile(new IronPython.Compiler.PythonCompilerOptions() { ModuleName = "__main__" });
292293

293-
int res = 0;
294+
ExceptionDispatchInfo exceptionInfo = null;
295+
296+
int res = -1;
294297
int maxStackSize = 2 * 1024 * 1024; // 2 MiB
295298
var thread = new Thread(() => {
296299
try {
@@ -301,12 +304,12 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc
301304
#pragma warning disable SYSLIB0006 // 'Thread.ResetAbort is not supported and throws PlatformNotSupportedException.'
302305
Thread.ResetAbort();
303306
#pragma warning restore SYSLIB0006
304-
} catch (Exception ex) when (ex.GetPythonException() is object pex) {
305-
if (DynamicHelpers.GetPythonType(pex).Name == "SkipTest") {
307+
} catch (Exception ex) {
308+
if (ex.GetPythonException() is object pex && DynamicHelpers.GetPythonType(pex).Name == "SkipTest") {
306309
NUnit.Framework.TestContext.Progress.WriteLine($"Test {testcase.Name} skipped: {pex}");
307310
res = 0;
308311
} else {
309-
throw;
312+
exceptionInfo = ExceptionDispatchInfo.Capture(ex);
310313
}
311314
}
312315
}, maxStackSize) {
@@ -324,6 +327,9 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc
324327
NUnit.Framework.TestContext.Error.WriteLine($"{testcase.Name} timed out after {testcase.Options.Timeout / 1000.0} seconds.");
325328
return -1;
326329
}
330+
331+
exceptionInfo?.Throw();
332+
327333
return res;
328334
} finally {
329335
Environment.CurrentDirectory = cwd;

0 commit comments

Comments
 (0)