Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes to make mutmut3 work with inline-snapshot #338

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions mutmut/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,15 @@ def guess_paths_to_mutate():
'Could not figure out where the code to mutate is. '
'Please specify it on the command line using --paths-to-mutate, '
'or by adding "paths_to_mutate=code_dir" in setup.cfg to the [mutmut] section.')

def limit_memory(maxsize):
soft, hard = resource.getrlimit(resource.RLIMIT_AS)
resource.setrlimit(resource.RLIMIT_AS, (maxsize, hard))


def record_trampoline_hit(name):
if getattr(mutmut,"config",None) is None:
return
if mutmut.config.max_stack_depth != -1:
f = inspect.currentframe()
c = mutmut.config.max_stack_depth
Expand Down Expand Up @@ -181,7 +187,7 @@ class BadTestExecutionCommandsException(Exception):

def _mutmut_trampoline(orig, mutants, *args, **kwargs):
import os
mutant_under_test = os.environ['MUTANT_UNDER_TEST']
mutant_under_test = os.environ.get('MUTANT_UNDER_TEST',"")
if mutant_under_test == 'fail':
from mutmut.__main__ import MutmutProgrammaticFailException
raise MutmutProgrammaticFailException('Failed programmatically')
Expand Down Expand Up @@ -669,10 +675,10 @@ def __init__(self, *, ids):

def clear_out_obsolete_test_names(self):
count_before = sum(len(x) for x in mutmut.tests_by_mangled_function_name)
mutmut.tests_by_mangled_function_name = {
mutmut.tests_by_mangled_function_name = defaultdict(set,{
k: {test_name for test_name in test_names if test_name in self.ids}
for k, test_names in mutmut.tests_by_mangled_function_name.items()
}
})
count_after = sum(len(x) for x in mutmut.tests_by_mangled_function_name)
if count_before != count_after:
print(f'Removed {count_before - count_after} obsolete test names')
Expand All @@ -688,6 +694,8 @@ def execute_pytest(self, params, **kwargs):
if mutmut.config.debug:
params = ['-vv'] + params
print('pytest: ', params, kwargs)

params += ["--rootdir=."]
exit_code = int(pytest.main(params, **kwargs))
if exit_code == 4:
raise BadTestExecutionCommandsException(params)
Expand Down Expand Up @@ -978,6 +986,8 @@ def s(key, default):
return default
if isinstance(default, list):
result = [x for x in result.split("\n") if x]
elif isinstance(default,bool):
result = result.lower() in ('1', 't', 'true')
elif isinstance(default, int):
result = int(result)
return result
Expand All @@ -999,7 +1009,7 @@ def read_config():
Path('tests.py'),
],
max_stack_depth=s('max_stack_depth', -1),
debug=s('debug', 'False').lower() in ('1', 't', 'true'),
debug=s('debug', False),
)


Expand Down Expand Up @@ -1097,7 +1107,7 @@ def collect_source_file_mutation_data(*, mutant_names):
source_file_mutation_data_by_path[str(path)] = m

mutants = [
(m, mutant_name, result)
(m, mutant_name.replace("src.", ""), result)
for path, m in source_file_mutation_data_by_path.items()
for mutant_name, result in m.exit_code_by_key.items()
]
Expand Down Expand Up @@ -1202,6 +1212,7 @@ def run(mutant_names, *, max_children):
os.environ['MUTANT_UNDER_TEST'] = ''
with CatchOutput(spinner_title='Running clean tests') as output_catcher:
tests = tests_for_mutant_names(mutant_names)


clean_test_exit_code = runner.run_tests(mutant_name=None, tests=tests)
if clean_test_exit_code != 0:
Expand Down Expand Up @@ -1257,6 +1268,7 @@ def read_one_child_exit_status():
# In the child
os.environ['MUTANT_UNDER_TEST'] = mutant_name
setproctitle(f'mutmut: {mutant_name}')
limit_memory(1000*1000*500)

# Run fast tests first
tests = sorted(tests, key=lambda test_name: mutmut.duration_by_test[test_name])
Expand Down
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pytest
mock>=2.0.0
coverage
whatthepatch==0.0.6
hammett
Loading