8000 Call PyErr_NormalizeException for exceptions by slide · Pull Request #1265 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Call PyErr_NormalizeException for exceptions #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for __init__ that causes exception
  • Loading branch information
slide committed Dec 11, 2020
commit caa09225c1bf029db2d66922ced2b23a0576bbbb
22 changes: 21 additions & 1 deletion src/embed_tests/TestPythonException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void TestPythonExceptionFormatNoTraceback()
}
catch (PythonException ex)
{
// ImportError/ModuleNotFoundError do not have a traceback when not running in a script
// ImportError/ModuleNotFoundError do not have a traceback when not running in a script
Assert.AreEqual(ex.StackTrace, ex.Format());
}
}
Expand All @@ -103,5 +103,25 @@ public void TestPythonExceptionFormatNormalized()
Assert.AreEqual("Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\nNameError: name 'b' is not defined\n", ex.Format());
}
}

[Test]
public void TestPythonExceptionFormatNormalizedWithExceptionIn__init__()
{
try
{
PythonEngine.Exec(@"
class TestException(NameError):
def __init__(self, val):
super().__init__(val)
x = int(val)

raise TestException('foo')
");
}
catch(PythonException ex)
{
Assert.AreEqual("Traceback (most recent call last):\n File \"<string>\", line 7, in <module>\n File \"<string>\", line 5, in __init__\nValueError: invalid literal for int() with base 10: 'foo'\n", ex.Format());
}
}
}
}
0