From 6acf000bf0ff8d2661ccc698b28f3539ef2c4e55 Mon Sep 17 00:00:00 2001 From: Adam Reeve Date: Mon, 1 Jul 2024 16:07:14 +1200 Subject: [PATCH] GH-43076: [C#] Upgrade Xunit and change how Python integration tests are skipped (#43091) ### Rationale for this change See #43076. The previous Xunit upgrade was reverted due to this breaking how the Python C Data Interface integration tests were skipped. It looks like this is unlikely to be fixed in xunit or xunit.skippablefact soon (see https://github.com/AArnott/Xunit.SkippableFact/issues/32), so I've refactored the tests to work around the issue. ### What changes are included in this PR? Re-update xunit to 2.8.1 and refactor the `CDataSchemaPythonTest` class construction so that skipping these tests when the `PYTHONNET_PYDLL` environment variable isn't set works again. ### Are these changes tested? Yes ### Are there any user-facing changes? No * GitHub Issue: #43076 Authored-by: Adam Reeve Signed-off-by: Curt Hagenlocher --- .../Apache.Arrow.Compression.Tests.csproj | 2 +- .../Apache.Arrow.Flight.Sql.Tests.csproj | 2 +- .../Apache.Arrow.Flight.Tests.csproj | 2 +- .../Apache.Arrow.Tests.csproj | 2 +- .../CDataInterfacePythonTests.cs | 34 +++++++++++++------ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/csharp/test/Apache.Arrow.Compression.Tests/Apache.Arrow.Compression.Tests.csproj b/csharp/test/Apache.Arrow.Compression.Tests/Apache.Arrow.Compression.Tests.csproj index 65ca360c97814..bd97372d1021b 100644 --- a/csharp/test/Apache.Arrow.Compression.Tests/Apache.Arrow.Compression.Tests.csproj +++ b/csharp/test/Apache.Arrow.Compression.Tests/Apache.Arrow.Compression.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/csharp/test/Apache.Arrow.Flight.Sql.Tests/Apache.Arrow.Flight.Sql.Tests.csproj b/csharp/test/Apache.Arrow.Flight.Sql.Tests/Apache.Arrow.Flight.Sql.Tests.csproj index 21ffe37cfa1af..5a5a92ccd2c7f 100644 --- a/csharp/test/Apache.Arrow.Flight.Sql.Tests/Apache.Arrow.Flight.Sql.Tests.csproj +++ b/csharp/test/Apache.Arrow.Flight.Sql.Tests/Apache.Arrow.Flight.Sql.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/csharp/test/Apache.Arrow.Flight.Tests/Apache.Arrow.Flight.Tests.csproj b/csharp/test/Apache.Arrow.Flight.Tests/Apache.Arrow.Flight.Tests.csproj index 3b00525a1ae18..132f17fa212a5 100644 --- a/csharp/test/Apache.Arrow.Flight.Tests/Apache.Arrow.Flight.Tests.csproj +++ b/csharp/test/Apache.Arrow.Flight.Tests/Apache.Arrow.Flight.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/csharp/test/Apache.Arrow.Tests/Apache.Arrow.Tests.csproj b/csharp/test/Apache.Arrow.Tests/Apache.Arrow.Tests.csproj index 71d7970f9ad7d..a3290e3be14ee 100644 --- a/csharp/test/Apache.Arrow.Tests/Apache.Arrow.Tests.csproj +++ b/csharp/test/Apache.Arrow.Tests/Apache.Arrow.Tests.csproj @@ -17,7 +17,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/csharp/test/Apache.Arrow.Tests/CDataInterfacePythonTests.cs b/csharp/test/Apache.Arrow.Tests/CDataInterfacePythonTests.cs index 274434e4bab09..fee18d165cdbd 100644 --- a/csharp/test/Apache.Arrow.Tests/CDataInterfacePythonTests.cs +++ b/csharp/test/Apache.Arrow.Tests/CDataInterfacePythonTests.cs @@ -31,24 +31,19 @@ namespace Apache.Arrow.Tests { public class CDataSchemaPythonTest : IClassFixture { - class PythonNet : IDisposable + public class PythonNet : IDisposable { + public bool Initialized { get; } + public PythonNet() { - bool inCIJob = Environment.GetEnvironmentVariable("GITHUB_ACTIONS") == "true"; - bool inVerificationJob = Environment.GetEnvironmentVariable("TEST_CSHARP") == "1"; bool pythonSet = Environment.GetEnvironmentVariable("PYTHONNET_PYDLL") != null; - // We only skip if this is not in CI - if (inCIJob && !inVerificationJob && !pythonSet) - { - throw new Exception("PYTHONNET_PYDLL not set; skipping C Data Interface tests."); - } - else + if (!pythonSet) { - Skip.If(!pythonSet, "PYTHONNET_PYDLL not set; skipping C Data Interface tests."); + Initialized = false; + return; } - PythonEngine.Initialize(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && @@ -57,6 +52,8 @@ public PythonNet() dynamic sys = Py.Import("sys"); sys.path.append(Path.Combine(Path.GetDirectoryName(Environment.GetEnvironmentVariable("PYTHONNET_PYDLL")), "DLLs")); } + + Initialized = true; } public void Dispose() @@ -65,6 +62,21 @@ public void Dispose() } } + public CDataSchemaPythonTest(PythonNet pythonNet) + { + if (!pythonNet.Initialized) + { + bool inCIJob = Environment.GetEnvironmentVariable("GITHUB_ACTIONS") == "true"; + bool inVerificationJob = Environment.GetEnvironmentVariable("TEST_CSHARP") == "1"; + + // Skip these tests if this is not in CI or is a verification job and PythonNet couldn't be initialized + Skip.If(inVerificationJob || !inCIJob, "PYTHONNET_PYDLL not set; skipping C Data Interface tests."); + + // Otherwise throw + throw new Exception("PYTHONNET_PYDLL not set; cannot run C Data Interface tests."); + } + } + private static Schema GetTestSchema() { using (Py.GIL())