You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upon looking mutations, I also fund another false positive: I have assert False in my code, in order to cover branches that are not intended to be hit. Changing them to true doesn't make much sense.
It also tried to mutate the string of the assert, which also does not make too much sense.
In general, I don't feel like it's that useful to test for mutations in asserts, as they are mostly a defensive measure (they can be disabled, after all).
str.rsplit behaves exactly like str.split, if maxsplit is not provided, so in that case there should be no mutation.
Yes, without the maxsplit argument this mutation cannot be detected by the tests. We should change not mutate in this case. If you want to take a shot at this, I would suggest to add another if m.matches(...) to the operator_string_methods_swap method (outside of the loop) and remove this dict entry.
Upon looking mutations, I also fund another false positive: I have assert False in my code, in order to cover branches that are not intended to be hit. Changing them to true doesn't make much sense.
It also tried to mutate the string of the assert, which also does not make too much sense.
I also do not think mutating assert false is useful. We could change this, but I think the change would not be trivial. Currently most (or all?) mutation operators do not rely on the context, so the mutation of False to True currently does not know if it is the operand of an assert statement. We could considert to add the parent metadata as additional context for operators.
So I'm not sure if this would be worth the effort. The mutation for assert False should only show up as a mutation that was not executed (similar to uncovered code with e.g. coverage.py).
In general, I don't feel like it's that useful to test for mutations in asserts, as they are mostly a defensive measure (they can be disabled, after all).
I guess people could use assert statements for quick and dirty input validation, for instance:
defsave_user(username, age):
assert0<=age<=150, 'Please provide an age between 0 and 150'
While this is not best practice, I could imagine code like this. For these cases, mutating assert statements seems reasonable to me. If this is really uncommon, we could consider not mutating assert statements, which would be rather simple to implement in mutmut.
So I'm not sure if this would be worth the effort. The mutation for assert False should only show up as a mutation that was not executed (similar to uncovered code with e.g. coverage.py).
That assertion comes up as fail. I noticed it due to that.
Maybe I misunderstood something, do you have a reproducible example?
My thinking is, that if the assert False is on unreachable code, then the mutation (assert True) should never be executed and thus reported as "no tests" (with the 🫥 emoji). And if it is reachable and executed in the tests, it probably makes sense to mutate it to assert True and check if a test is influenced by this.
For the issue regarding assert statements, the problem is that we only track coverage per function rather than per line. I have created a separate issue: #395
Activity
fabi321 commentedon May 30, 2025
Upon looking mutations, I also fund another false positive: I have assert False in my code, in order to cover branches that are not intended to be hit. Changing them to true doesn't make much sense.
It also tried to mutate the string of the assert, which also does not make too much sense.
In general, I don't feel like it's that useful to test for mutations in asserts, as they are mostly a defensive measure (they can be disabled, after all).
Otto-AA commentedon Jun 1, 2025
Yes, without the maxsplit argument this mutation cannot be detected by the tests. We should change not mutate in this case. If you want to take a shot at this, I would suggest to add another
if m.matches(...)to the operator_string_methods_swap method (outside of the loop) and remove this dict entry.I also do not think mutating
assert falseis useful. We could change this, but I think the change would not be trivial. Currently most (or all?) mutation operators do not rely on the context, so the mutation ofFalsetoTruecurrently does not know if it is the operand of anassertstatement. We could considert to add the parent metadata as additional context for operators.So I'm not sure if this would be worth the effort. The mutation for
assert Falseshould only show up as a mutation that was not executed (similar to uncovered code with e.g. coverage.py).I guess people could use
assertstatements for quick and dirty input validation, for instance:While this is not best practice, I could imagine code like this. For these cases, mutating
assertstatements seems reasonable to me. If this is really uncommon, we could consider not mutatingassertstatements, which would be rather simple to implement in mutmut.fabi321 commentedon Jun 1, 2025
That assertion comes up as fail. I noticed it due to that.
Otto-AA commentedon Jun 1, 2025
Maybe I misunderstood something, do you have a reproducible example?
My thinking is, that if the
assert Falseis on unreachable code, then the mutation (assert True) should never be executed and thus reported as "no tests" (with the 🫥 emoji). And if it is reachable and executed in the tests, it probably makes sense to mutate it toassert Trueand check if a test is influenced by this.fabi321 commentedon Jun 1, 2025
I don't have any minimal example, but mutmut marks https://github.com/stormworks-utils/tumfl/blob/main/tumfl/parser.py#L490 as fail, and coverage reports that that line is never hit.
(Or rather, it would mark it, twice (due to the string mut), if it didn't have the
no mut)CHB-0r1s commentedon Jun 13, 2025
@fabi321 @Otto-AA Hi! Can you explain your point: split = rsplit without args, so we need check here?
As string mutations was my add-on, I try to help with fix it, if it may be helpful
Otto-AA commentedon Jun 20, 2025
The split issue is fixed with #394 .
For the issue regarding
assertstatements, the problem is that we only track coverage per function rather than per line. I have created a separate issue: #395