8000 Fix PythonTestRunner to work with new pytest setup · pythonnet/pythonnet@f0011a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit f0011a5

Browse files
committed
Fix PythonTestRunner to work with new pytest setup
1 parent d46fa1e commit f0011a5

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/python_tests_runner/Python.PythonTestsRunner.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<ProjectReference Include="..\runtime\Python.Runtime.csproj" />
9+
<ProjectReference Include="..\testing\Python.Test.csproj" />
910
</ItemGroup>
1011

1112
<ItemGroup>

src/python_tests_runner/PythonTestRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using NUnit.Framework;
99

1010
using Python.Runtime;
11+
using Python.Test;
1112

1213
namespace Python.PythonTestsRunner
1314
{
@@ -50,7 +51,7 @@ public void RunPythonTest(string testFile, string testName)
5051
{
5152
folder = Path.GetDirectoryName(folder);
5253
}
53-
folder = Path.Combine(folder, "tests");
54+
folder = Path.Combine(folder, "..", "tests");
5455
string path = Path.Combine(folder, testFile + ".py");
5556
if (!File.Exists(path)) throw new FileNotFoundException("Cannot find test file", path);
5657

tests/conftest.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def pytest_addoption(parser):
3131

3232
def pytest_configure(config):
3333
global bin_path
34+
if "clr" in sys.modules:
35+
# Already loaded (e.g. by the C# test runner), skip build
36+
import clr
37+
clr.AddReference("Python.Test")
38+
return
39+
3440
runtime_opt = config.getoption("runtime")
3541

3642
test_proj_path = os.path.join(cwd, "..", "src", "testing")
@@ -70,7 +76,10 @@ def pytest_configure(config):
7076

7177
def pytest_unconfigure(config):
7278
global bin_path
73-
shutil.rmtree(bin_path)
79+
try:
80+
shutil.rmtree(bin_path)
81+
except Exception:
82+
pass
7483

7584
def pytest_report_header(config):
7685
"""Generate extra report headers"""

0 commit comments

Comments
 (0)
0