Skip to content

Commit b6c8b6b

Browse files
committed
add action to view tests for mutant
1 parent 9d40df0 commit b6c8b6b

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
@@ -1336,6 +1336,7 @@ class ResultBrowser(App):
13361336
("f", "retest_function()", "Retest function"),
13371337
("m", "retest_module()", "Retest module"),
13381338
("a", "apply_mutant()", "Apply mutant to disk"),
1339+
("t", "view_tests()", "View tests for mutant"),
13391340
]
13401341

13411342
columns = [
@@ -1432,23 +1433,26 @@ def on_data_table_row_highlighted(self, event):
14321433
estimated_duration = source_file_mutation_data.estimated_time_of_tests_by_mutant.get(mutant_name, '?')
14331434
duration = source_file_mutation_data.durations_by_key.get(mutant_name, '?')
14341435

1436+
view_tests_description = f'(press t to view tests executed for this mutant)'
1437+
14351438
match status:
14361439
case 'killed':
1437-
description = f'Killed ({exit_code=}): Mutant got detected by a test.'
1440+
description = f'Killed ({exit_code=}): Mutant caused a test to fail 🎉'
14381441
case 'survived':
1439-
description = f'Survived ({exit_code=}): No test detected this mutant.'
1442+
description = f'Survived ({exit_code=}): No test detected this mutant. {view_tests_description}'
14401443
case 'skipped':
14411444
description = f'Skipped ({exit_code=})'
14421445
case 'check was interrupted by user':
1443-
description = f'User interrupt ({exit_code=})'
1446+
description = f'User interrupted ({exit_code=})'
14441447
case 'timeout':
1445-
description = f'Timeout ({exit_code=}): Timed out because tests did not finish within {duration:.3f} seconds. Tests without mutation took {estimated_duration:.3f} seconds.'
1448+
description = (f'Timeout ({exit_code=}): Timed out because tests did not finish within {duration:.3f} seconds. '
1449+
f'Tests without mutation took {estimated_duration:.3f} seconds. {view_tests_description}')
14461450
case 'no tests':
14471451
description = f'Untested ({exit_code=}): Skipped because selected tests do not execute this code.'
14481452
case 'segfault':
14491453
description = f'Segfault ({exit_code=}): Running pytest with this mutant segfaulted.'
14501454
case 'suspicious':
1451-
description = f'Unknown ({exit_code=}): Unknown pytest exit code'
1455+
description = f'Unknown ({exit_code=}): Running pytest with this mutant resulted in an unknown exit code.'
14521456
case 'not checked':
14531457
description = 'Not checked in the last mutmut run.'
14541458
case _:
@@ -1471,10 +1475,18 @@ def load_thread():
14711475
t.start()
14721476

14731477
def retest(self, pattern):
1478+
self._run_subprocess_command('run', [pattern])
1479+
1480+
def view_tests(self, mutant_name: str):
1481+
self._run_subprocess_command('tests-for-mutant', [mutant_name])
1482+
1483+
def _run_subprocess_command(self, command: str, args: list[str]):
14741484
with self.suspend():
14751485
browse_index = sys.argv.index('browse')
14761486
initial_args = sys.argv[:browse_index]
1477-
subprocess.run([sys.executable, *initial_args, 'run', pattern])
1487+
subprocess_args = [sys.executable, *initial_args, command, *args]
1488+
print('>', *subprocess_args)
1489+
subprocess.run(subprocess_args)
14781490
input('press enter to return to browser')
14791491

14801492
self.read_data()
@@ -1505,6 +1517,9 @@ def action_apply_mutant(self):
15051517
return
15061518
apply_mutant(mutants_table.get_row_at(mutants_table.cursor_row)[0])
15071519

1520+
def action_view_tests(self):
1521+
self.view_tests(self.get_mutant_name_from_selection())
1522+
15081523
ResultBrowser().run()
15091524

15101525

0 commit comments

Comments
 (0)