Skip to content

wip: don't mutate lines excluded from coverage - #547

Open
nedbat wants to merge 3 commits into
boxed:mainfrom
nedbat:nedbat/excluded-coverage
Open

wip: don't mutate lines excluded from coverage#547
nedbat wants to merge 3 commits into
boxed:mainfrom
nedbat:nedbat/excluded-coverage

Conversation

@nedbat

@nedbat nedbat commented Aug 4, 2026

Copy link
Copy Markdown

Written by Claude. I haven't reviewed it.

@nedbat

nedbat commented Aug 7, 2026

Copy link
Copy Markdown
Author

This now does what I needed it to do. I had code like this:

match something:
    ...

    case _NEVER:
        raise RuntimeError("Not implemented!")

and I have a coverage setting to exclude case _NEVER: clauses. mutmut was mutating those cases by deleting them, and the tests wouldn't fail, because those cases never ran, as expected.

With this pull request, those cases are not mutated, because the coverage analysis is used to understand that they are excluded.

@nedbat
nedbat marked this pull request as ready for review August 7, 2026 15:38
Comment thread src/mutmut/mutation/file_mutation.py Outdated
(m for m in mutated_methods if m.line_number_start <= error.line_number <= m.line_number_end), None
)
if mutant is None:
continue

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here to prevent #541 from stopping the run.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, removed this.

@boxed

boxed commented Aug 9, 2026

Copy link
Copy Markdown
Owner

I looked through this a bit and it looks like a good improvement. The tests fail though, I guess that's because of the workaround for #541 ?

@boxed

boxed commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Great. This is merge-ready now then? Seems like an improvement over the code on main at least.

@nedbat

nedbat commented Aug 9, 2026

Copy link
Copy Markdown
Author

I don't know of a reason not to merge it. I really haven't read the code I'm sorry to say. I understand if you'd want to hold off.

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

Successfully merging this pull request may close these issues.

2 participants