### Install Dependencies with uv Source: https://github.com/boxed/mutmut/blob/main/CONTRIBUTING.rst Use this command to synchronize and install project dependencies using uv. ```console uv sync ``` -------------------------------- ### Install Local Mutmut for Poetry Projects Source: https://github.com/boxed/mutmut/blob/main/CONTRIBUTING.rst Install your local, editable version of Mutmut for projects managed with Poetry, and then install project dependencies. ```console poetry add --group dev --editable pip install -r /requirements.txt ``` -------------------------------- ### Install and Run mutmut Source: https://github.com/boxed/mutmut/blob/main/README.rst Basic commands to install the package and initiate a mutation test run. ```console pip install mutmut mutmut run ``` -------------------------------- ### Run Mutation Testing Source: https://github.com/boxed/mutmut/blob/main/e2e_projects/benchmark_1k/README.md Navigate to the benchmark directory and execute the mutmut run command to start mutation testing. ```bash cd e2e_projects/benchmark_1k mutmut run ``` -------------------------------- ### Run Linting and Formatting Source: https://github.com/boxed/mutmut/blob/main/CONTRIBUTING.rst Apply linting and formatting checks across all files using ruff and pre-commit. Install pre-commit hooks for automatic checks on commit. ```console uv run pre-commit run --all-files ``` ```bash pre-commit install ``` -------------------------------- ### Install Local Mutmut for Pip Projects Source: https://github.com/boxed/mutmut/blob/main/CONTRIBUTING.rst Install your local, editable version of Mutmut for projects managed with pip. ```console python -m pip install --editable ``` -------------------------------- ### Suppressing mutations across a range of lines Source: https://github.com/boxed/mutmut/blob/main/README.rst Use 'no mutate start' and 'no mutate end' to suppress mutations across a specific range of lines regardless of indentation. ```python a = mutate_this() # pragma: no mutate start b = skip_this() c = skip_this_too() # pragma: no mutate end d = mutate_this_too() ``` -------------------------------- ### Configure mutmut via setup.cfg Source: https://github.com/boxed/mutmut/blob/main/README.rst Define source paths and test selection arguments in the project's setup.cfg file. ```ini [mutmut] source_paths=src/ pytest_add_cli_args_test_selection=tests/ ``` -------------------------------- ### Configure mutmut via pyproject.toml Source: https://github.com/boxed/mutmut/blob/main/README.rst Define configuration settings using the tool.mutmut section in pyproject.toml. ```toml [tool.mutmut] source_paths = [ "src/" ] pytest_add_cli_args_test_selection= [ "tests/" ] ``` -------------------------------- ### Configure Extra Files to Copy Source: https://github.com/boxed/mutmut/blob/main/README.rst Specify additional files or directories required for the test suite to run correctly. ```ini also_copy= iommi/snapshots/ conftest.py ``` -------------------------------- ### Configure dependency change behavior Source: https://github.com/boxed/mutmut/blob/main/README.rst Set the action to take when a watched dependency file changes. ```toml on_dependency_change = "warn" ``` -------------------------------- ### Run Benchmark Comparison Source: https://github.com/boxed/mutmut/blob/main/e2e_projects/benchmark_1k/README.md Execute the benchmark comparison script to test mutmut's performance across different strategies. ```bash python run_benchmark.py ``` -------------------------------- ### View Benchmark Results Source: https://github.com/boxed/mutmut/blob/main/e2e_projects/benchmark_1k/README.md Display the mutation testing summary results in a formatted JSON output. ```bash cat mutants/summary.json | python -m json.tool ``` -------------------------------- ### Configure Test Delay for Benchmark Source: https://github.com/boxed/mutmut/blob/main/e2e_projects/benchmark_1k/README.md Run the benchmark script with a specified test delay to simulate per-test runtime costs. ```bash python run_benchmark.py --test-delay 0.01 ``` -------------------------------- ### Run Tests in a Container Source: https://github.com/boxed/mutmut/blob/main/CONTRIBUTING.rst Execute the test suite within a Linux container, as done in CI. ```bash ./scripts/run_tests.sh ``` -------------------------------- ### Configure mutation timeout settings Source: https://github.com/boxed/mutmut/blob/main/README.rst Adjust the timeout parameters used to kill slow mutations. ```toml # Configure how long mutmut waits before killing a slow mutation # Currently calculated as (duration_of_original_tests + timeout_constant) * timeout_multiplier seconds timeout_constant = 1.0 timeout_multiplier = 15.0 ``` -------------------------------- ### Enable debug output Source: https://github.com/boxed/mutmut/blob/main/README.rst Set to true to display detailed test output during mutation runs. ```text debug=true ``` -------------------------------- ### Run Mutants with Wildcards Source: https://github.com/boxed/mutmut/blob/main/README.rst Target specific modules or functions for mutation testing using Unix-style filename patterns. ```console mutmut run "my_module*" mutmut run "my_module.my_function*" ``` -------------------------------- ### Run Tests with pytest Source: https://github.com/boxed/mutmut/blob/main/CONTRIBUTING.rst Execute all project tests using pytest. For updating inline snapshots, append `--inline-snapshot=fix`. ```console uv run pytest ``` ```console uv run pytest --inline-snapshot=fix ``` -------------------------------- ### Disable setproctitle on macOS Source: https://github.com/boxed/mutmut/blob/main/README.rst Configure process title settings in pyproject.toml to avoid potential segfaults on macOS. ```toml # pyproject.toml [tool.mutmut] use_setproctitle = false ``` -------------------------------- ### Enable coverage-based mutation Source: https://github.com/boxed/mutmut/blob/main/README.rst Set this configuration to restrict mutations only to lines identified as covered by coverage.py. ```text mutate_only_covered_lines=true ``` -------------------------------- ### Configure type checker integration Source: https://github.com/boxed/mutmut/blob/main/README.rst Define the command used to run type checkers like pyrefly or mypy to filter out invalid mutants. ```python # for pyrefly type_check_command = ['pyrefly', 'check', '--output-format=json'] # for mypy type_check_command = ['mypy', 'your_source_dir', '--output', 'json', '--disable-error-code', 'unused-ignore'] ``` -------------------------------- ### Configure cache invalidation files Source: https://github.com/boxed/mutmut/blob/main/README.rst Specify additional files to watch for changes using glob patterns. ```toml cache_invalidation_files = [ "queries/*.sql", "config/*.yaml" ] ``` -------------------------------- ### Exclude Files from Mutation Source: https://github.com/boxed/mutmut/blob/main/README.rst Define inclusion and exclusion patterns for files during the mutation process. ```ini only_mutate= src/api/* src/services/* do_not_mutate= *__tests.py ``` -------------------------------- ### Skip mutation for functions or classes Source: https://github.com/boxed/mutmut/blob/main/docs/index.md Place the pragma inline on the definition line to skip the entire node and its children. ```python def complex_algorithm(): # pragma: no mutate block return some_complex_calculation() class MySettings: # pragma: no mutate block DEBUG = True MAX_RETRIES = 3 ``` -------------------------------- ### Skip mutation for a single line Source: https://github.com/boxed/mutmut/blob/main/README.rst Use the pragma comment to prevent mutation on a specific line of code. ```python some_code_here() # pragma: no mutate ``` -------------------------------- ### Configure cache invalidation exclusions Source: https://github.com/boxed/mutmut/blob/main/README.rst Exclude specific files or directories from triggering cache invalidation. ```toml cache_invalidation_exclude = [ "*.json", "fixtures/snapshots/*" ] ``` -------------------------------- ### Exclude code via regex patterns Source: https://github.com/boxed/mutmut/blob/main/README.rst Define patterns in pyproject.toml to skip mutation for specific expressions matching the provided regex. ```toml # pyproject.toml [tool.mutmut] do_not_mutate_patterns = [ # disable mutations of all logger.info/debug/... statements 'logger\.\w+', # disable mutating exceptions 'raise \w+', ] ``` -------------------------------- ### Limit Stack Depth Source: https://github.com/boxed/mutmut/blob/main/README.rst Restrict mutation testing relevance to tests within a specific stack depth to improve performance. ```ini max_stack_depth=8 ``` -------------------------------- ### Skip mutation for function bodies Source: https://github.com/boxed/mutmut/blob/main/docs/index.md Place the pragma on its own line inside a function to suppress mutation of the body while keeping the definition mutable. ```python def foo(val=1): # pragma: no mutate block x = 1 y = complex_calculation() z = x + y def bar(): # this function is still mutated normally return 42 ``` -------------------------------- ### Skip mutation for if-branches Source: https://github.com/boxed/mutmut/blob/main/docs/index.md Inline the pragma on an if-statement to suppress only that branch, leaving sibling branches mutable. ```python if error_condition: # pragma: no mutate block log_error() send_alert() elif other_condition: # still mutated -- this branch is outside the block scope handle_other() else: # still mutated handle_success() ``` -------------------------------- ### Modifying pytest arguments Source: https://github.com/boxed/mutmut/blob/main/README.rst Configure pytest behavior by setting specific variables for CLI arguments and file copies. ```python # for CLI args that select or deselect tests, use `pytest_add_cli_args_test_selection` pytest_add_cli_args_test_selection = ["-m", "not fail", "-k", "test_include"] # for other CLI args, use `pytest_add_cli_args` pytest_add_cli_args = ["-p", "no:some_plugin"] # disable a plugin pytest_add_cli_args = ["-o", "xfail_strict=False"] # overrides xfail_strict from your normal config # if you want to ignore the normal pytest configuration # you can specify a diferent pytest ini file to be used pytest_add_cli_args = ["-c", "mutmut_pytest.ini"] also_copy = ["mutmut_pytest.ini"] ``` -------------------------------- ### Disable git change detection Source: https://github.com/boxed/mutmut/blob/main/README.rst Turn off automatic git-based change detection to use the fallback list. ```toml use_git_change_detection = false ``` -------------------------------- ### Suppressing mutations with pragmas Source: https://github.com/boxed/mutmut/blob/main/README.rst Use the 'no mutate block' pragma to exclude entire functions, classes, or specific if-branches from mutation testing. ```python def complex_algorithm(): # pragma: no mutate block return some_complex_calculation() class MySettings: # pragma: no mutate block DEBUG = True MAX_RETRIES = 3 ``` ```python def foo(val=1): # pragma: no mutate block x = 1 y = complex_calculation() z = x + y def bar(): # this function is still mutated normally return 42 ``` ```python if error_condition: # pragma: no mutate block log_error() send_alert() elif other_condition: # still mutated -- this branch is outside the block scope handle_other() else: # still mutated handle_success() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.