Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xunit 2.8.1 broke compatibility with skipping tests from fixtures #32

Closed
adamreeve opened this issue Jun 28, 2024 · 3 comments
Closed

Comments

@adamreeve
Copy link

I reported this at xunit/xunit#2965 but was told it's an issue for SkippableFact. Is this something that can be fixed or do we need to find another way to achieve this?

Test class:

using Xunit;

namespace XunitTest;

public class UnitTest1 : IClassFixture<UnitTest1.MyFixture>
{
    class MyFixture
    {
        public MyFixture()
        {
            bool runTests = false;
            Skip.If(!runTests, "Skipping");
        }
    }

    [SkippableFact]
    public void Test1()
    {
        Assert.Equal(1, 1);
    }
}

csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
    <PackageReference Include="xunit" Version="2.8.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="xunit.skippablefact" Version="1.4.13" />
  </ItemGroup>

</Project>

With Xunit 2.8.0, running dotnet test gives:

$ dotnet test
  Determining projects to restore...
  Restored /home/adam/dev/tmp/XunitTest/XunitTest.csproj (in 196 ms).
  XunitTest -> /home/adam/dev/tmp/XunitTest/bin/Debug/net8.0/XunitTest.dll
Test run for /home/adam/dev/tmp/XunitTest/bin/Debug/net8.0/XunitTest.dll (.NETCoreApp,Version=v8.0)
Microsoft (R) Test Execution Command Line Tool Version 17.8.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.12]     XunitTest.UnitTest1.Test1 [SKIP]
  Skipped XunitTest.UnitTest1.Test1 [1 ms]

Skipped! - Failed:     0, Passed:     0, Skipped:     1, Total:     1, Duration: < 1 ms - XunitTest.dll (net8.0)

With 2.8.1 I get:

$ dotnet test
  Determining projects to restore...
  Restored /home/adam/dev/tmp/XunitTest/XunitTest.csproj (in 211 ms).
  XunitTest -> /home/adam/dev/tmp/XunitTest/bin/Debug/net8.0/XunitTest.dll
Test run for /home/adam/dev/tmp/XunitTest/bin/Debug/net8.0/XunitTest.dll (.NETCoreApp,Version=v8.0)
Microsoft (R) Test Execution Command Line Tool Version 17.8.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.13]     XunitTest.UnitTest1.Test1 [FAIL]
  Failed XunitTest.UnitTest1.Test1 [1 ms]
  Error Message:
   Class fixture type 'XunitTest.UnitTest1+MyFixture' threw in its constructor
---- Xunit.SkipException : Skipping
  Stack Trace:
  
----- Inner Stack Trace -----
   at XunitTest.UnitTest1.MyFixture..ctor() in /home/adam/dev/tmp/XunitTest/UnitTest1.cs:line 12
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: < 1 ms - XunitTest.dll (net8.0)
@AArnott
Copy link
Owner

AArnott commented Jun 28, 2024

Interesting. I never considered skipping from a fixture, so that wasn't an intentional feature.
I hope we can get it working again for you, but I don't anticipate having time to investigate soon. Do you have interest in investigating this?

@adamreeve
Copy link
Author

I don't really have time to investigate this either. We can work around it by adding a constructor to the test class and skipping from there instead, so I'm happy if you want to close this as not supported, but I thought it was worth reporting at least.

CurtHagenlocher pushed a commit to apache/arrow that referenced this issue Jul 1, 2024
…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 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: #43076

Authored-by: Adam Reeve <[email protected]>
Signed-off-by: Curt Hagenlocher <[email protected]>
@bradwilson
Copy link
Contributor

More discussion back in the original issue, but suffice to say that I believe this isn't a bug in SkippableFact. Throwing from fixtures and having it propagate down into the test itself was an unintentional bug that got fixed in 2.8.1. Throwing fixtures should've always prevented the test from running, and that's now the case in 2.8.1 (the previously bug was that it only failed if you accepted that fixture from the constructor of the unit test).

@AArnott AArnott closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2024
zanmato1984 pushed a commit to zanmato1984/arrow that referenced this issue Jul 9, 2024
…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 <[email protected]>
Signed-off-by: Curt Hagenlocher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants