Skip to content

Commit 3cd39fa

Browse files
authored
Merge pull request #408 from souradeep-das/souradeep/add_tests_dir
feat: add tests_dir to config
2 parents 22f3924 + 3e52e5e commit 3cd39fa

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

e2e_projects/config/config_pkg/math.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ def call_depth_four():
1111
return call_depth_five() - 1
1212

1313
def call_depth_five():
14-
return 5
14+
return 5
15+
16+
def func_with_no_tests():
17+
return 420

e2e_projects/config/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ paths_to_mutate = [ "config_pkg/" ]
2828
do_not_mutate = [ "*ignore*" ]
2929
also_copy = [ "data" ]
3030
max_stack_depth=8 # Includes frames by mutmut, see https://github.com/boxed/mutmut/issues/378
31-
# NOTE: as of writing, the following options are not implemented
32-
# tests_dir = [ "my_tests/" ]
31+
tests_dir = [ "tests/main/" ]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from config_pkg.math import func_with_no_tests
2+
3+
def test_func_with_no_tests():
4+
assert func_with_no_tests() == 420

mutmut/__main__.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,34 @@ def pytest_runtest_makereport(self, item, call):
400400

401401
stats_collector = StatsCollector()
402402

403+
pytest_args = ['-x', '-q']
404+
if tests:
405+
pytest_args += list(tests)
406+
else:
407+
tests_dir = mutmut.config.tests_dir
408+
if tests_dir:
409+
pytest_args += tests_dir
403410
with change_cwd('mutants'):
404-
return int(self.execute_pytest(['-x', '-q'] + list(tests), plugins=[stats_collector]))
411+
return int(self.execute_pytest(pytest_args, plugins=[stats_collector]))
405412

406413
def run_tests(self, *, mutant_name, tests):
414+
pytest_args = ['-x', '-q']
415+
if tests:
416+
pytest_args += list(tests)
417+
else:
418+
tests_dir = mutmut.config.tests_dir
419+
if tests_dir:
420+
pytest_args += tests_dir
407421
with change_cwd('mutants'):
408-
return int(self.execute_pytest(['-x', '-q'] + list(tests)))
422+
return int(self.execute_pytest(pytest_args))
409423

410424
def run_forced_fail(self):
425+
pytest_args = ['-x', '-q']
426+
tests_dir = mutmut.config.tests_dir
427+
if tests_dir:
428+
pytest_args += tests_dir
411429
with change_cwd('mutants'):
412-
return int(self.execute_pytest(['-x', '-q']))
430+
return int(self.execute_pytest(pytest_args))
413431

414432
def list_all_tests(self):
415433
class TestsCollector:
@@ -418,8 +436,13 @@ def pytest_collection_modifyitems(self, items):
418436

419437
collector = TestsCollector()
420438

439+
tests_dir = mutmut.config.tests_dir
440+
pytest_args = ['-x', '-q', '--collect-only']
441+
if tests_dir:
442+
pytest_args += tests_dir
443+
421444
with change_cwd('mutants'):
422-
exit_code = int(self.execute_pytest(['-x', '-q', '--collect-only'], plugins=[collector]))
445+
exit_code = int(self.execute_pytest(pytest_args, plugins=[collector]))
423446
if exit_code != 0:
424447
raise CollectTestsFailedException()
425448

@@ -623,6 +646,7 @@ class Config:
623646
max_stack_depth: int
624647
debug: bool
625648
paths_to_mutate: List[Path]
649+
tests_dir: List[str] = None
626650

627651
def should_ignore_for_mutation(self, path):
628652
if not str(path).endswith('.py'):
@@ -701,7 +725,8 @@ def load_config():
701725
paths_to_mutate=[
702726
Path(y)
703727
for y in s('paths_to_mutate', [])
704-
] or guess_paths_to_mutate()
728+
] or guess_paths_to_mutate(),
729+
tests_dir=s('tests_dir', []),
705730
)
706731

707732

tests/e2e/snapshots/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"config_pkg.math.x_call_depth_three__mutmut_2": 1,
1313
"config_pkg.math.x_call_depth_four__mutmut_1": 33,
1414
"config_pkg.math.x_call_depth_four__mutmut_2": 33,
15-
"config_pkg.math.x_call_depth_five__mutmut_1": 33
15+
"config_pkg.math.x_call_depth_five__mutmut_1": 33,
16+
"config_pkg.math.x_func_with_no_tests__mutmut_1": 33
1617
}
1718
}

0 commit comments

Comments
 (0)