Skip to content

Commit 1febb52

Browse files
committed
early exit when stats find no tests for any mutant
1 parent 86b77dd commit 1febb52

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

mutmut/__main__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ def start(self):
689689

690690
def dump_output(self):
691691
self.stop()
692+
print()
692693
for line in self.strings:
693694
print(line, end='')
694695

@@ -820,6 +821,18 @@ def run_stats_collection(runner, tests=None):
820821
output_catcher.dump_output()
821822
print(f'failed to collect stats. runner returned {collect_stats_exit_code}')
822823
exit(1)
824+
# ensure that at least one mutant has associated tests
825+
num_associated_tests = sum(len(tests) for tests in mutmut.tests_by_mangled_function_name.values())
826+
if num_associated_tests == 0:
827+
output_catcher.dump_output()
828+
print('Stopping early, because we could not find any test case for any mutant. It seems that the selected tests do not cover any code that we mutated.')
829+
if not mutmut.config.debug:
830+
print('You can set debug=true to see the executed test names in the output above.')
831+
else:
832+
print('In the last pytest run above, you can see which tests we executed.')
833+
print('You can use mutmut browse to check which parts of the source code we mutated.')
834+
print('If some of the mutated code should be covered by the executed tests, consider opening an issue (with a MRE if possible).')
835+
exit(1)
823836

824837
print(' done')
825838
if not tests: # again, meaning all

0 commit comments

Comments
 (0)