Skip to content

xUnit test runner fails to find module dictionary #372

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

Closed
vmuriart opened this issue Feb 9, 2017 · 12 comments
Closed

xUnit test runner fails to find module dictionary #372

vmuriart opened this issue Feb 9, 2017 · 12 comments

Comments

@vmuriart
Copy link
Contributor

vmuriart commented Feb 9, 2017

Environment

  • Pythonnet version: v2.2.2
  • Python version: all
  • Operating System: Windows

Details

  • Describe what you were trying to get done.

Replace nUnit to xUnit framework.

Below is one of the tests rewritten for xUnit


using System.Collections.Generic;
using Xunit;
using Python.Runtime;

namespace Python.EmbeddingTest
{
    public class PyIterTest
    {
        [Fact]
        public void TestOnPyList()
        {
            using (Py.GIL())
            {
                var list = new PyList();
                list.Append(new PyString("foo"));
                list.Append(new PyString("bar"));
                list.Append(new PyString("baz"));
                var result = new List<string>();
                foreach (PyObject item in list)
                {
                    result.Add(item.ToString());
                }
                Assert.Equal(3, result.Count);
                Assert.Equal("foo", result[0]);
                Assert.Equal("bar", result[1]);
                Assert.Equal("baz", result[2]);
            }
        }
    }
}
  • If there was a crash, please include the traceback here.
Error msg: Fatal Python error: PyImport_GetModuleDict: no module dictionary!
@vmuriart
Copy link
Contributor Author

vmuriart commented Feb 9, 2017

Submitting this since this is a completely different issue that the ones we saw with nUnit and mstests. I was testing it as an alternative for #371 and found a different slew of issues.

The goal of this issue is to understand why pythonnet is behaving this way when being run from xUnit.

@den-run-ai
Copy link
Contributor

Don't you need to shutdown the interpreter in the teardown?

@vmuriart
Copy link
Contributor Author

failed with and without it. I converted and rewrote the entire test suite and tried it multiple ways, none of them worked. This was just one of the simplest ways to reproduce it

@den-run-ai
Copy link
Contributor

@vmuriart did you try xunit locally? with debugger?

@den-run-ai
Copy link
Contributor

According to this SO answer, it is likely that some CPython threads are killed during process exit, that's why we get these errors:

http://stackoverflow.com/questions/17679715/fatal-python-error-pyimport-getmoduledict-no-module-dictionary

@vmuriart
Copy link
Contributor Author

Nice find! We still have pending issues w our finalizers. This & the NUnit App unloading are related to it most likely

@den-run-ai
Copy link
Contributor

@vmuriart yep, one of my comments in finalizer pull request was ignored (i hope it does not cause deadlocks):

https://github.com/pythonnet/pythonnet/pull/365/files/c954442c3f2ae594ca318f298ebd4607ea7fab3d#r99997577

@vmuriart
Copy link
Contributor Author

vmuriart commented Feb 10, 2017

Did you hit submit on the review? I don't see any comment, and I been having issues w the review holding my comments until i submit my review

@den-run-ai
Copy link
Contributor

den-run-ai commented Feb 10, 2017 via email

@vmuriart
Copy link
Contributor Author

image

It doesn't show a review or comment from you. Didn't ignore it on purpose.
The commit actually is preventing the lockup that was causing the previous crash. But there is still more work need to properly fix the issue.

@vmuriart
Copy link
Contributor Author

vmuriart commented Mar 24, 2017

This looks to be yet another issue w gc. If only 1 test is run, test will run, pass but xUnit will not exit, just hang. If two tests are run, then xUnit will crash and/or hang. This can be similarly reproduced on NUnit by using --dispose-runners option.

xUnit by default disposes of its objects after every test. NUnit on the other hand doesn't really, and --dispose-runners forces objects to be disposed after being used; meant to be used on system with low resources.

@filmor
Copy link
Member

filmor commented Aug 6, 2021

We don't use xUnit (anymore).

@filmor filmor closed this as completed Aug 6, 2021
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

No branches or pull requests

3 participants