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

How to exclude a line without the block it introduces? #1797

Open
Apakottur opened this issue Jun 18, 2024 · 0 comments
Open

How to exclude a line without the block it introduces? #1797

Apakottur opened this issue Jun 18, 2024 · 0 comments
Labels
support A support question from a user

Comments

@Apakottur
Copy link

Apakottur commented Jun 18, 2024

I am working on a big project where we often use the the match statement like so:

match something:
    case type_1():
        logic_1()
    case type_2():
        logic_2():
    case _:
        assert_never(something)

In this code example the default case should never happen, but sometimes we also have:

match something:
    case type_1():
        logic_1()
    case type_2():
        logic_2():
    case _:
        print("Default case")

When running coverage, I want to exclude all the assert_never lines because they should never run, so I use this configuration option:

exclude_lines =
    assert_never

This removes these lines from the coverage report, but the case _ lines are still reported as missing.

If I do this:

exclude_lines =
    case _

Then the entire block is excluded, including the print statement, which I do want to ensure coverage on.

Another approach is to use the # pragma: no cover comment, but we have hundreds of these cases and that would be very inconvenient to use.

How can I configure coverage to exclude case _ when the only thing I have inside is assert_never, but not exclude it in other cases?

@Apakottur Apakottur added the support A support question from a user label Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support A support question from a user
Projects
None yet
Development

No branches or pull requests

1 participant