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

Skip to content

Commit d28e39f

Browse files
dsefilmor
dse
authored andcommitted
Bug: Py_Initialize/Py_Finalize calls during alive PythonEngine. Fixed.
1 parent ded3b4e commit d28e39f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/embed_tests/TestRuntime.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
using System;
1+
using System;
22
using NUnit.Framework;
33
using Python.Runtime;
44

55
namespace Python.EmbeddingTest
66
{
77
public class TestRuntime
88
{
9+
[OneTimeSetUp]
10+
public void SetUp()
11+
{
12+
// We needs to ensure that no any engines are running.
13+
if (PythonEngine.IsInitialized)
14+
{
15+
PythonEngine.Shutdown();
16+
}
17+
}
18+
919
/// <summary>
1020
/// Test the cache of the information from the platform module.
1121
///
@@ -24,12 +34,12 @@ public static void PlatformCache()
2434

2535
// Don't shut down the runtime: if the python engine was initialized
2636
// but not shut down by another test, we'd end up in a bad state.
27-
}
37+
}
2838

2939
[Test]
3040
public static void Py_IsInitializedValue()
3141
{
32-
Runtime.Runtime.Py_Finalize(); // In case another test left it on.
42+
Runtime.Runtime.Py_Finalize();
3343
Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized());
3444
Runtime.Runtime.Py_Initialize();
3545
Assert.AreEqual(1, Runtime.Runtime.Py_IsInitialized());

0 commit comments

Comments
 (0)