Skip to content

xUnit test runner fails to find module dictionary #372

Closed

Description

@vmuriart

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!

Activity

  1. vmuriart commented on Feb 9, 2017

    @vmuriart
    ContributorAuthor

    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.

  2. den-run-ai commented on Feb 9, 2017

    @den-run-ai
    Contributor

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

  3. vmuriart commented on Feb 10, 2017

    @vmuriart
    ContributorAuthor

    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

  4. den-run-ai commented on Feb 10, 2017

    @den-run-ai
    Contributor

    @vmuriart did you try xunit locally? with debugger?

  5. den-run-ai commented on Feb 10, 2017

    @den-run-ai
    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

  6. vmuriart commented on Feb 10, 2017

    @vmuriart
    ContributorAuthor

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

  7. den-run-ai commented on Feb 10, 2017

    @den-run-ai
    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

  8. vmuriart commented on Feb 10, 2017

    @vmuriart
    ContributorAuthor

    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

  9. den-run-ai commented on Feb 10, 2017

    @den-run-ai
    Contributor
  10. vmuriart commented on Feb 10, 2017

    @vmuriart
    ContributorAuthor

    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.

  11. vmuriart commented on Mar 24, 2017

    @vmuriart
    ContributorAuthor

    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.

  12. filmor commented on Aug 6, 2021

    @filmor
    Member

    We don't use xUnit (anymore).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions