Skip to content

Commit

Permalink
apacheGH-43076: [C#] Upgrade Xunit and change how Python integration …
Browse files Browse the repository at this point in the history
…tests are skipped (apache#43091)

### Rationale for this change

See apache#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 AArnott/Xunit.SkippableFact#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: apache#43076

Authored-by: Adam Reeve <adreeve@gmail.com>
Signed-off-by: Curt Hagenlocher <curt@hagenlocher.org>
  • Loading branch information
adamreeve authored and zanmato1984 committed Jul 9, 2024
1 parent 6f9529f commit 6acf000
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion csharp/test/Apache.Arrow.Tests/Apache.Arrow.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
34 changes: 23 additions & 11 deletions csharp/test/Apache.Arrow.Tests/CDataInterfacePythonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,19 @@ namespace Apache.Arrow.Tests
{
public class CDataSchemaPythonTest : IClassFixture<CDataSchemaPythonTest.PythonNet>
{
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) &&
Expand All @@ -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()
Expand All @@ -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())
Expand Down

0 comments on commit 6acf000

Please sign in to comment.