Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1a1a9ab
Drop unused requirements.txt
filmor Feb 16, 2026
4ca65d6
Bump astral-sh/setup-uv from 6 to 7 (#2656)
dependabot[bot] Oct 28, 2025
0856eb4
Bump actions/checkout from 5 to 6 (#2663)
dependabot[bot] Nov 24, 2025
a7d0842
Only init/shutdown Python once
filmor Oct 22, 2025
f6ff431
Disable NUnit analyzer for now
filmor Oct 23, 2025
9fc08f3
Reset conversions after each codec test
filmor Oct 23, 2025
a8e5020
Remove shutdown from most tests, disable the rest for now
filmor Oct 23, 2025
0a6062e
Use python -m pytest, path seemingly not properly updated
filmor Oct 26, 2025
6b1bb92
Remove unused architecture from uv env activation
filmor Oct 26, 2025
d4d1768
Synchronize the environment
filmor Oct 26, 2025
40a3db7
Include the probed PythonDLL value in the exception
filmor Dec 7, 2025
96f428f
Use the actual pytest runner
filmor Dec 7, 2025
5459ac7
Move tests that require reinit and only run on .NET Framework
filmor Dec 8, 2025
abb6855
Bump NUnit3TestAdapter from 5.2.0 to 6.0.0 (#2667)
dependabot[bot] Dec 8, 2025
9882788
Fix line endings
filmor Dec 9, 2025
dc5c6c4
Add previous commit to ignore file
filmor Dec 9, 2025
caac33d
Initial 3.14 commit
filmor Aug 9, 2025
e10d333
Apply alignment fix
filmor Oct 22, 2025
e976558
Disable problematic GC tests
filmor Oct 22, 2025
65af098
Set ht_token to NULL in Python 3.14
filmor Oct 24, 2025
e244503
Fix lockfile
filmor Oct 26, 2025
8e0333d
Assign True instead of None to __clear_reentry_guard__
filmor Dec 6, 2025
cd108b8
Disable the three remaining failing tests
filmor Dec 6, 2025
698bf00
Take the GIL in sequence and list wrappers
filmor Dec 7, 2025
908e13b
Move tp_clear workaround to .NET
filmor Dec 7, 2025
c851b3a
Skip coreclr embedded tests for now
filmor Dec 7, 2025
08550d0
Workaround for blocked PyObject_GenericSetAttr in metatypes
filmor Dec 7, 2025
f1d90f3
Revert changes to tests
filmor Dec 7, 2025
a47555d
Bump macos image version and add arm64
filmor Dec 8, 2025
cebfd15
Reenable .NET Core embedding tests
filmor Dec 9, 2025
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
Move tests that require reinit and only run on .NET Framework
  • Loading branch information
filmor committed Feb 24, 2026
commit 5459ac75d4292c503cd37f7cf11a7556124c6651
28 changes: 28 additions & 0 deletions src/embed_tests/NeedsReinit/StopAndRestartEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Python.Runtime;
using NUnit.Framework;

namespace Python.EmbeddingTest.NeedsReinit;

public class StopAndRestartEngine
{
bool WasInitialized = false;

[OneTimeSetUp]
public void Setup()
{
WasInitialized = PythonEngine.IsInitialized;
if (WasInitialized)
{
PythonEngine.Shutdown();
}
}

[OneTimeTearDown]
public void Teardown()
{
if (WasInitialized && !PythonEngine.IsInitialized)
{
PythonEngine.Initialize();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
// Unfortunately this means no continuous integration testing for this case.
//
#if NETFRAMEWORK
namespace Python.EmbeddingTest
namespace Python.EmbeddingTest.NeedsReinit
{
class TestDomainReload
[Category("NeedsReinit")]
class TestDomainReload : StopAndRestartEngine
{


abstract class CrossCaller : MarshalByRefObject
{
public abstract ValueType Execute(ValueType arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using NUnit.Framework;
using Python.Runtime;

namespace Python.EmbeddingTest
namespace Python.EmbeddingTest.NeedsReinit
{
[Ignore("Only works if we can re-initialize the Python engine")]
public class PyInitializeTest
[Category("NeedsReinit")]
public class TestPyInitialize : StopAndRestartEngine
{
/// <summary>
/// Tests issue with multiple simple Initialize/Shutdowns.
Expand Down
133 changes: 133 additions & 0 deletions src/embed_tests/NeedsReinit/TestPythonEngineProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using NUnit.Framework;
using Python.Runtime;

namespace Python.EmbeddingTest.NeedsReinit
{
[Category("NeedsReinit")]
public class TestPythonEngineProperties : StopAndRestartEngine
{
[Test]
public void SetPythonHome()
{
PythonEngine.Initialize();
var pythonHomeBackup = PythonEngine.PythonHome;
PythonEngine.Shutdown();

if (pythonHomeBackup == "")
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");

var pythonHome = "/dummypath/";

PythonEngine.PythonHome = pythonHome;
PythonEngine.Initialize();

Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
PythonEngine.Shutdown();

// Restoring valid pythonhome.
PythonEngine.PythonHome = pythonHomeBackup;
}

[Test]
public void SetPythonHomeTwice()
{
PythonEngine.Initialize();
var pythonHomeBackup = PythonEngine.PythonHome;
PythonEngine.Shutdown();

if (pythonHomeBackup == "")
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");

var pythonHome = "/dummypath/";

PythonEngine.PythonHome = "/dummypath2/";
PythonEngine.PythonHome = pythonHome;
PythonEngine.Initialize();

Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
PythonEngine.Shutdown();

PythonEngine.PythonHome = pythonHomeBackup;
}

[Test]
[Ignore("Currently buggy in Python")]
public void SetPythonHomeEmptyString()
{
PythonEngine.Initialize();

var backup = PythonEngine.PythonHome;
if (backup == "")
{
PythonEngine.Shutdown();
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
}
PythonEngine.PythonHome = "";

Assert.AreEqual("", PythonEngine.PythonHome);

PythonEngine.PythonHome = backup;
PythonEngine.Shutdown();
}

[Test]
public void SetProgramName()
{
if (PythonEngine.IsInitialized)
{
PythonEngine.Shutdown();
}

var programNameBackup = PythonEngine.ProgramName;

var programName = "FooBar";

PythonEngine.ProgramName = programName;
PythonEngine.Initialize();

Assert.AreEqual(programName, PythonEngine.ProgramName);
PythonEngine.Shutdown();

PythonEngine.ProgramName = programNameBackup;
}

[Test]
public void SetPythonPath()
{
PythonEngine.Initialize();

const string moduleName = "pytest";
bool importShouldSucceed;
try
{
Py.Import(moduleName);
importShouldSucceed = true;
}
catch
{
importShouldSucceed = false;
}

string[] paths = Py.Import("sys").GetAttr("path").As<string[]>();
string path = string.Join(System.IO.Path.PathSeparator.ToString(), paths);

// path should not be set to PythonEngine.PythonPath here.
// PythonEngine.PythonPath gets the default module search path, not the full search path.
// The list sys.path is initialized with this value on interpreter startup;
// it can be (and usually is) modified later to change the search path for loading modules.
// See https://docs.python.org/3/c-api/init.html#c.Py_GetPath
// After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.

PythonEngine.Shutdown();

PythonEngine.PythonPath = path;
PythonEngine.Initialize();

Assert.AreEqual(path, PythonEngine.PythonPath);
if (importShouldSucceed) Py.Import(moduleName);

PythonEngine.Shutdown();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@
using NUnit.Framework;
using Python.Runtime;

namespace Python.EmbeddingTest
namespace Python.EmbeddingTest.NeedsReinit
{
[Ignore("Only works if we can shutdown and re-initialize the Python runtime")]
public class TestRuntime
[Ignore("Tests for low-level Runtime functions, crashing currently")]
public class TestRuntime : StopAndRestartEngine
{
[OneTimeSetUp]
public void SetUp()
{
// We needs to ensure that no any engines are running.
if (PythonEngine.IsInitialized)
{
PythonEngine.Shutdown();
}
}

[Test]
public static void Py_IsInitializedValue()
{
Expand Down
5 changes: 5 additions & 0 deletions src/embed_tests/Python.EmbeddingTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<None Include="fixtures/**/*.py" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<!-- Drop Reinit test source files for net8.0 and above -->
<ItemGroup Condition="'$(TargetFramework)' != 'net472'">
<Compile Remove="NeedsReinit/*.cs" />
</ItemGroup>

<PropertyGroup>
<DefineConstants>$(DefineConstants);$(ConfiguredConstants)</DefineConstants>
</PropertyGroup>
Expand Down
127 changes: 0 additions & 127 deletions src/embed_tests/TestPythonEngineProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,132 +96,5 @@ public static void GetPythonHomeDefault()

Assert.AreEqual(envPythonHome, enginePythonHome);
}

[Ignore("Only works if we can shutdown and re-init the interpreter")]
[Test]
public void SetPythonHome()
{
PythonEngine.Initialize();
var pythonHomeBackup = PythonEngine.PythonHome;
PythonEngine.Shutdown();

if (pythonHomeBackup == "")
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");

var pythonHome = "/dummypath/";

PythonEngine.PythonHome = pythonHome;
PythonEngine.Initialize();

Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
PythonEngine.Shutdown();

// Restoring valid pythonhome.
PythonEngine.PythonHome = pythonHomeBackup;
}

[Ignore("Only works if we can shutdown and re-init the interpreter")]
[Test]
public void SetPythonHomeTwice()
{
PythonEngine.Initialize();
var pythonHomeBackup = PythonEngine.PythonHome;
PythonEngine.Shutdown();

if (pythonHomeBackup == "")
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");

var pythonHome = "/dummypath/";

PythonEngine.PythonHome = "/dummypath2/";
PythonEngine.PythonHome = pythonHome;
PythonEngine.Initialize();

Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
PythonEngine.Shutdown();

PythonEngine.PythonHome = pythonHomeBackup;
}

[Test]
[Ignore("Currently buggy in Python")]
public void SetPythonHomeEmptyString()
{
PythonEngine.Initialize();

var backup = PythonEngine.PythonHome;
if (backup == "")
{
PythonEngine.Shutdown();
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
}
PythonEngine.PythonHome = "";

Assert.AreEqual("", PythonEngine.PythonHome);

PythonEngine.PythonHome = backup;
PythonEngine.Shutdown();
}

[Ignore("Only works if we can shutdown and re-init the interpreter")]
[Test]
public void SetProgramName()
{
if (PythonEngine.IsInitialized)
{
PythonEngine.Shutdown();
}

var programNameBackup = PythonEngine.ProgramName;

var programName = "FooBar";

PythonEngine.ProgramName = programName;
PythonEngine.Initialize();

Assert.AreEqual(programName, PythonEngine.ProgramName);
PythonEngine.Shutdown();

PythonEngine.ProgramName = programNameBackup;
}

[Ignore("Only works if we can shutdown and re-init the interpreter")]
[Test]
public void SetPythonPath()
{
PythonEngine.Initialize();

const string moduleName = "pytest";
bool importShouldSucceed;
try
{
Py.Import(moduleName);
importShouldSucceed = true;
}
catch
{
importShouldSucceed = false;
}

string[] paths = Py.Import("sys").GetAttr("path").As<string[]>();
string path = string.Join(System.IO.Path.PathSeparator.ToString(), paths);

// path should not be set to PythonEngine.PythonPath here.
// PythonEngine.PythonPath gets the default module search path, not the full search path.
// The list sys.path is initialized with this value on interpreter startup;
// it can be (and usually is) modified later to change the search path for loading modules.
// See https://docs.python.org/3/c-api/init.html#c.Py_GetPath
// After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.

PythonEngine.Shutdown();

PythonEngine.PythonPath = path;
PythonEngine.Initialize();

Assert.AreEqual(path, PythonEngine.PythonPath);
if (importShouldSucceed) Py.Import(moduleName);

PythonEngine.Shutdown();
}
}
}