Add context manager protocol for .NET IDisposable types by den-run-ai · Pull Request #2568 · pythonnet/pythonnet

For anyone else who is annoyed that the test failures do not provoke backtraces on GitHub's UI,1 here is the output:

_______________________ test_import_all_on_second_time ________________________

    def test_import_all_on_second_time():
        """Test import all attributes after a normal import without '*'.
        Due to import * only allowed at module level, the test body splitted
        to a module file."""
>       from . import importtest

tests\test_import.py:20: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    import sys
    try:
        del sys.modules["System.IO"]
    except KeyError:
        pass
    
    assert "FileStream" not in globals()
    import System.IO
    from System.IO import *
    
>   assert "FileStream" in globals()
E   AssertionError

tests\importtest.py:13: AssertionError

My (uninitiated) interpretation is that some cruft is left hanging around despite the Dispose() call.

Footnotes

  1. And also lest the test artefacts age away.