Skip to content

Commit fad78fd

Browse files
committed
Only list selected tests
Necessary if we run `mutmut run` twice with some pytest_add_cli_args_test_selection.
1 parent 0f9f6d7 commit fad78fd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

mutmut/__main__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def execute_pytest(self, params: list[str], **kwargs):
435435
params = ['--rootdir=.'] + params + self._pytest_add_cli_args
436436
if mutmut.config.debug:
437437
params = ['-vv'] + params
438-
print('python -m pytest ', ' '.join(params))
438+
print('python -m pytest ', ' '.join([f'"{param}"' for param in params]))
439439
exit_code = int(pytest.main(params, **kwargs))
440440
if mutmut.config.debug:
441441
print(' exit code', exit_code)
@@ -486,8 +486,15 @@ def run_forced_fail(self):
486486

487487
def list_all_tests(self):
488488
class TestsCollector:
489+
def __init__(self):
490+
self.collected_nodeids = set()
491+
self.deselected_nodeids = set()
492+
489493
def pytest_collection_modifyitems(self, items):
490-
self.nodeids = {item.nodeid for item in items}
494+
self.collected_nodeids |= {item.nodeid for item in items}
495+
496+
def pytest_deselected(self, items):
497+
self.deselected_nodeids |= {item.nodeid for item in items}
491498

492499
collector = TestsCollector()
493500

@@ -499,7 +506,8 @@ def pytest_collection_modifyitems(self, items):
499506
if exit_code != 0:
500507
raise CollectTestsFailedException()
501508

502-
return ListAllTestsResult(ids=collector.nodeids)
509+
selected_nodeids = collector.collected_nodeids - collector.deselected_nodeids
510+
return ListAllTestsResult(ids=selected_nodeids)
503511

504512

505513
class HammettRunner(TestRunner):

0 commit comments

Comments
 (0)