FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Python tests can now be debugged by running them as embedded tests within NUnit by tminka · Pull Request #1341 · pythonnet/pythonnet · GitHub

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

Merged
lostmsu merged 4 commits into
pythonnet:masterfrom
tminka:TestPythonTest
Jan 5, 2021
Merged

Python tests can now be debugged by running them as embedded tests within NUnit#1341
lostmsu merged 4 commits into
pythonnet:masterfrom
tminka:TestPythonTest

Conversation

tminka commented Dec 31, 2020

Copy link
Copy Markdown
Contributor

What does this implement/fix? Explain your changes.

When debugging a problem such as issue #1325, it is immensely useful to have the Visual Studio debugger stop at the location of the error. This is tricky to do with pytest, even when running pytest from Visual Studio. Running the test via Python.Exec makes debugging simple and easy. You don't need to re-install Python.NET every time you make a change. You don't need to edit project options, and you don't need to figure out how to run pytest from Visual Studio.

With this change, you can just type in the name of the python test you want to debug, build the solution, and debug the new NUnit test that appears.

Does this close any currently open issues?

No

Any other comments?

No

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

lostmsu commented Dec 31, 2020

Copy link
Copy Markdown
Member

These must not be run during CI. As I suggested, this should be a separate project file.

tminka commented Dec 31, 2020
edited
Loading

Copy link
Copy Markdown
Contributor Author

Why can't they run during CI? They do test the embedding system. Also, it is important that this setup is not broken by some other change.

lostmsu commented Dec 31, 2020

Copy link
Copy Markdown
Member

That makes sense. But still I would put them into a separate project file.

Comment thread appveyor.yml
Comment thread src/embed_python_tests/packages.config Outdated

tminka commented Dec 31, 2020

Copy link
Copy Markdown
Contributor Author

It appears that Py.Import("pytest") is failing on some platforms, for reasons unrelated to this PR. Any ideas?

Comment thread .github/workflows/main.yml Outdated

lostmsu commented Jan 1, 2021

Copy link
Copy Markdown
Member

@tminka I think the cause might be that the OS image running actions in CI has Python 3.8 installed as system Python, and when embed tests are running, it is being picked up instead of the one in custom environment.

lostmsu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sorry, just noticed the issue with skipped Shutdown

tminka commented Jan 3, 2021

Copy link
Copy Markdown
Contributor Author

@lostmsu I don't think it is picking up the wrong Python installation because an earlier commit showed the value of sys.path in the embedded tests:

Python.Runtime.PythonException : ImportError : No module named pytest when sys.path=/opt/hostedtoolcache/Python/3.8.6/x64/lib/python38.zip:/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8:/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/lib-dynload:/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages:/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.10/:/home/runner/work/pythonnet/pythonnet/src:/home/runner/work/pythonnet/pythonnet/src/tests/fixtures:/home/runner/work/pythonnet/pythonnet/src:/home/runner/work/pythonnet/pythonnet/src/tests/fixtures

The "Install dependencies" step installed pytest into /opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages which is on that path.

lostmsu commented Jan 4, 2021

Copy link
Copy Markdown
Member

@tminka since you moved python test running from .NET to a separate project and CI step, you no longer need the changes to TestPythonEngineProperties.cs for the purposes this PR is trying to achieve. Moving it to a separate PR should let us merge the runner.

tminka commented Jan 4, 2021

Copy link
Copy Markdown
Contributor Author

I agree, but I think the change to importhook is important enough (and harmless enough) to keep in this PR.

Comment thread src/runtime/importhook.cs Outdated
if (!(mt is ModuleObject))
{
Exceptions.SetError(Exceptions.ImportError, $"No module named {name}");
Exceptions.SetError(Exceptions.ImportError, originalExceptionMessage);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Use PythonException.Restore()

lostmsu merged commit 96cc739 into pythonnet:master Jan 5, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL