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

ExcludeFromCodeCoverage ignored for method in generic class that returns an IAsyncEnumerable #1431

Closed
daveMueller opened this issue Jan 8, 2023 · 2 comments · Fixed by #1542
Labels
stale waiting for customer Waiting for customer action with repro Issue with repro

Comments

@daveMueller
Copy link
Collaborator

    Seeing similar behavior where a Generic Class has a method that returns an `IAsyncEnumerable`, the method is marked with `ExcludeFromCodeCoverage` however coverage is reported as zero instead of being ignored.

Originally posted by @RobARichardson in #1383 (comment)

@daveMueller
Copy link
Collaborator Author

@RobARichardson sorry I can't reproduce it. As a repro I have https://github.com/daveMueller/CoverletIssue1431 with coverlet 3.2.0:

public class Class1<T>
{
    public static async IAsyncEnumerable<int> Demo()
    {
        yield return 5;
    }
}

Without the [ExcludeFromCodeCoverage] attribute I get a coverage report with following content:

    <package name="CoverletIssue1431" line-rate="1" branch-rate="0.5" complexity="4">
      <classes>
        <class name="CoverletIssue1431.Class1`1/&lt;Demo&gt;d__0" filename="Repos\CoverletIssue1431\CoverletIssue1431\Class1.cs" line-rate="1" branch-rate="0.5" complexity="4">
          <methods>
            <method name="MoveNext" signature="()" line-rate="1" branch-rate="0.5" complexity="4">
              <lines>
                <line number="9" hits="1" branch="True" condition-coverage="50% (1/2)">
                  <conditions>
                    <condition number="31" type="jump" coverage="50%" />
                  </conditions>
                </line>
                <line number="10" hits="1" branch="True" condition-coverage="50% (1/2)">
                  <conditions>
                    <condition number="79" type="jump" coverage="50%" />
                  </conditions>
                </line>
                <line number="11" hits="1" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="9" hits="1" branch="True" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="31" type="jump" coverage="50%" />
              </conditions>
            </line>
            <line number="10" hits="1" branch="True" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="79" type="jump" coverage="50%" />
              </conditions>
            </line>
            <line number="11" hits="1" branch="False" />
          </lines>
        </class>
      </classes>
    </package>

After adding the attribute:

public class Class1<T>
{
    [ExcludeFromCodeCoverage]
    public static async IAsyncEnumerable<int> Demo()
    {
        yield return 5;
    }
}

I get an empty coverage report which is the expected result.

<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="1" branch-rate="1" version="1.9" timestamp="1673254959" lines-covered="0" lines-valid="0" branches-covered="0" branches-valid="0">
  <sources />
  <packages>
    <package name="CoverletIssue1431" line-rate="1" branch-rate="1" complexity="0">
      <classes />
    </package>
  </packages>
</coverage>

@RobARichardson could you provide a repro for us to further investigate the issue?

@daveMueller daveMueller added waiting for customer Waiting for customer action with repro Issue with repro and removed untriaged To be investigated labels Jan 9, 2023
@github-actions
Copy link

github-actions bot commented Sep 3, 2023

This issue is stale because it has been open for 3 months with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale waiting for customer Waiting for customer action with repro Issue with repro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant