Skip to content

Commit fa123f5

Browse files
committed
add action to view tests for mutant
1 parent dc4327e commit fa123f5

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

mutmut/__main__.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,7 @@ class ResultBrowser(App):
13231323
("f", "retest_function()", "Retest function"),
13241324
("m", "retest_module()", "Retest module"),
13251325
("a", "apply_mutant()", "Apply mutant to disk"),
1326+
("t", "view_tests()", "View tests for mutant"),
13261327
]
13271328

13281329
columns = [
@@ -1419,23 +1420,26 @@ def on_data_table_row_highlighted(self, event):
14191420
estimated_duration = source_file_mutation_data.estimated_time_of_tests_by_mutant.get(mutant_name, '?')
14201421
duration = source_file_mutation_data.durations_by_key.get(mutant_name, '?')
14211422

1423+
view_tests_description = f'(press t to view tests executed for this mutant)'
1424+
14221425
match status:
14231426
case 'killed':
1424-
description = f'Killed ({exit_code=}): Mutant got detected by a test.'
1427+
description = f'Killed ({exit_code=}): Mutant caused a test to fail 🎉'
14251428
case 'survived':
1426-
description = f'Survived ({exit_code=}): No test detected this mutant.'
1429+
description = f'Survived ({exit_code=}): No test detected this mutant. {view_tests_description}'
14271430
case 'skipped':
14281431
description = f'Skipped ({exit_code=})'
14291432
case 'check was interrupted by user':
1430-
description = f'User interrupt ({exit_code=})'
1433+
description = f'User interrupted ({exit_code=})'
14311434
case 'timeout':
1432-
description = f'Timeout ({exit_code=}): Timed out because tests did not finish within {duration:.3f} seconds. Tests without mutation took {estimated_duration:.3f} seconds.'
1435+
description = (f'Timeout ({exit_code=}): Timed out because tests did not finish within {duration:.3f} seconds. '
1436+
f'Tests without mutation took {estimated_duration:.3f} seconds. {view_tests_description}')
14331437
case 'no tests':
14341438
description = f'Untested ({exit_code=}): Skipped because selected tests do not execute this code.'
14351439
case 'segfault':
14361440
description = f'Segfault ({exit_code=}): Running pytest with this mutant segfaulted.'
14371441
case 'suspicious':
1438-
description = f'Unknown ({exit_code=}): Unknown pytest exit code'
1442+
description = f'Unknown ({exit_code=}): Running pytest with this mutant resulted in an unknown exit code.'
14391443
case 'not checked':
14401444
description = 'Not checked in the last mutmut run.'
14411445
case _:
@@ -1458,10 +1462,18 @@ def load_thread():
14581462
t.start()
14591463

14601464
def retest(self, pattern):
1465+
self._run_subprocess_command('run', [pattern])
1466+
1467+
def view_tests(self, mutant_name: str):
1468+
self._run_subprocess_command('tests-for-mutant', [mutant_name])
1469+
1470+
def _run_subprocess_command(self, command: str, args: list[str]):
14611471
with self.suspend():
14621472
browse_index = sys.argv.index('browse')
14631473
initial_args = sys.argv[:browse_index]
1464-
subprocess.run([sys.executable, *initial_args, 'run', pattern])
1474+
subprocess_args = [sys.executable, *initial_args, command, *args]
1475+
print('>', *subprocess_args)
1476+
subprocess.run(subprocess_args)
14651477
input('press enter to return to browser')
14661478

14671479
self.read_data()
@@ -1492,6 +1504,9 @@ def action_apply_mutant(self):
14921504
return
14931505
apply_mutant(mutants_table.get_row_at(mutants_table.cursor_row)[0])
14941506

1507+
def action_view_tests(self):
1508+
self.view_tests(self.get_mutant_name_from_selection())
1509+
14951510
ResultBrowser().run()
14961511

14971512

0 commit comments

Comments
 (0)