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
{{ message }}
Repository navigation
Non-tested statements can be reported as "survived" (🙁) instead of "no tests" (🫥) #395
# my_libdefhello() ->str:
return"Hello from my-lib!"print('hello')
# test_my_libfrommy_libimporthellodeftest_hello():
asserthello() =="Hello from my-lib!"
We would create mutations for the print('hello') and report them as survived. However, this statement is (and cannot) be executed by the tests, so it should be reported as "no tests".
The cause of this issue is that we collect coverage only on a function level, not on a statement/expression level. So currently, with the stats collected by _mutmut_trampoline we do know that hello() has been executed, but we do not know which statements inside of hello have been executed.
The reason I implemented the custom method to know which functions are called instead of using coverage is that coverage used to be slow. I think that's no longer the case with the latest updates. Although some test to verify might be in order.
Yes, we should test performance on some repositories before merging a switch to coverage.py. I would guess that it reduces the overall runtime in projects that do not have 100% coverage, because we can skip more untested mutants and thus skip multiple complete test runs. But let's see how it works out in practice.
I don't think I have time to work on this in the next weeks, so if someone else wants to give it a shot, go for it! Some starting pointers:
I am going to try and implement this because I have the same issue. I have low coverage on my project with many functions covered, but not every line in them. I don't want those (uncovered) lines to be mutated. Not just for speed, but mostly because the report on them is useless to me (and they dominate the report)
I will use the guide above -- if there's anything more you'd like to add, let me know.
Something I'm not sure about yet is whether coverage.py can be used to get the stack depth (for the max_stack_depth config option). Currently we track this here:
If we cannot implement max_stack_depth with coverage.py, we probably want to keep the current stats collection in addition to an (optional?) coverage.py tracking. I think it would still be good to fill tests_by_mangled_function_name based on the more precise coverage results, but I'm not 100% sure this is necessary.
Also, I'm not sure whether we should run coverage.py on the original source code or the already mutated one. I would tend to running it before mutating. If we would run it afterwards, (1) the mapping of covered line number to mutant name could be tricky, and (2) we generate useless mutants. See ARCHITECTURE.rst for info on the current phases.
And another pointer: we already use line numbers to honour the # pragma: no mutate comments. The logic to skip mutants based on the coverage could be similar, except that you need to read the data from some coverage report.
If this gets too complex, I would suggest to simply use the results of coverage.py like an automatic # pragma: no mutate on the uncovered lines, and keep the internals of mutmut like they are (eg don't touching the stats collection).
I think that would already be a good improvement and easier to implement :)
Activity
Otto-AA commentedon Jun 20, 2025
I currently see two approaches:
coverage.pyinstead of our custom coverage-tracking)assert Falsestatements,assert_never(), maybe more)The first one seems better, as it is not based on a heuristic that defines which code is untested. but is likely more effort to implement.
boxed commentedon Jun 21, 2025
The reason I implemented the custom method to know which functions are called instead of using coverage is that coverage used to be slow. I think that's no longer the case with the latest updates. Although some test to verify might be in order.
Otto-AA commentedon Jun 21, 2025
Yes, we should test performance on some repositories before merging a switch to
coverage.py. I would guess that it reduces the overall runtime in projects that do not have 100% coverage, because we can skip more untested mutants and thus skip multiple complete test runs. But let's see how it works out in practice.I don't think I have time to work on this in the next weeks, so if someone else wants to give it a shot, go for it! Some starting pointers:
mutmut/mutmut/__main__.py
Line 712 in 2710f93
mutmut/mutmut/trampoline_templates.py
Line 61 in 2710f93
elif mutant_under_test == 'stats':special casecoverage.pybefore the test run and stop it afterwards (https://coverage.readthedocs.io/en/latest/api.html; probably with dynamic contexts to track which test executed which mutants). Maybe we would need to run it on the non-mutated code, so we can easily cross-reference the line numbers with the mutants.loufranco commentedon Sep 9, 2025
I am going to try and implement this because I have the same issue. I have low coverage on my project with many functions covered, but not every line in them. I don't want those (uncovered) lines to be mutated. Not just for speed, but mostly because the report on them is useless to me (and they dominate the report)
I will use the guide above -- if there's anything more you'd like to add, let me know.
Otto-AA commentedon Sep 9, 2025
Thanks for taking a look at this!
Something I'm not sure about yet is whether coverage.py can be used to get the stack depth (for the max_stack_depth config option). Currently we track this here:
mutmut/mutmut/__main__.py
Line 131 in 2710f93
If we cannot implement max_stack_depth with coverage.py, we probably want to keep the current stats collection in addition to an (optional?) coverage.py tracking. I think it would still be good to fill
tests_by_mangled_function_namebased on the more precise coverage results, but I'm not 100% sure this is necessary.Also, I'm not sure whether we should run coverage.py on the original source code or the already mutated one. I would tend to running it before mutating. If we would run it afterwards, (1) the mapping of covered line number to mutant name could be tricky, and (2) we generate useless mutants. See ARCHITECTURE.rst for info on the current phases.
And another pointer: we already use line numbers to honour the
# pragma: no mutatecomments. The logic to skip mutants based on the coverage could be similar, except that you need to read the data from some coverage report.Otto-AA commentedon Sep 9, 2025
If this gets too complex, I would suggest to simply use the results of coverage.py like an automatic
# pragma: no mutateon the uncovered lines, and keep the internals of mutmut like they are (eg don't touching the stats collection).I think that would already be a good improvement and easier to implement :)
loufranco commentedon Sep 9, 2025
That makes a lot of sense to me (the automatic pragma: no mutate based on running coverage on the original source).
loufranco commentedon Sep 11, 2025
I made #438 to address this. It works on my project (and tests), but let me know if there are things I need to incorporate