Skip to content

Python tests can now be debugged by running them as embedded tests within NUnit #1341

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 4 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
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
ImportHook preserves the original exception message when an import fails
  • Loading branch information
tminka committed Jan 5, 2021
commit 0ccc443d905afa56f04ec48ffdfddf61b3a13955
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ jobs:
run: dotnet test --runtime any-${{ matrix.platform }} src/embed_tests/
if: ${{ matrix.os != 'macos' }} # Not working right now, doesn't find libpython

- name: Python tests runner
- name: Python tests run from .NET
run: dotnet test --runtime any-${{ matrix.platform }} src/python_tests_runner/
if: ${{ matrix.os != 'macos' }} # Not working right now, doesn't find libpython
if: ${{ matrix.os == 'windows' }} # Not working for others right now

# TODO: Run perf tests
# TODO: Run mono tests on Windows?
5 changes: 4 additions & 1 deletion src/runtime/importhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
// We don't support them anyway
return IntPtr.Zero;
}
// Save the exception
var originalException = new PythonException();
var originalExceptionMessage = originalException.ToString();
// Otherwise, just clear the it.
Exceptions.Clear();

Expand Down Expand Up @@ -342,7 +345,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
ManagedType mt = tail.GetAttribute(name, true);
if (!(mt is ModuleObject))
{
Exceptions.SetError(Exceptions.ImportError, $"No module named {name}");
Exceptions.SetError(Exceptions.ImportError, originalExceptionMessage);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use PythonException.Restore()

return IntPtr.Zero;
}
if (head == null)
Expand Down