boxed / mutmut

Mutation testing system
https://mutmut.readthedocs.io
BSD 3-Clause "New" or "Revised" License
923 stars 112 forks source link

error: BadTestExecutionCommandsException #340

Open adam-moss opened 1 week ago

adam-moss commented 1 week ago

Hi,

I'm trying to introduce mutmut into an existing project but am failing to get it to run with:

.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 694, in execute_pytest
    raise BadTestExecutionCommandsException(params)
mutmut.__main__.BadTestExecutionCommandsException: ['--doctest-glob=*.md', '--doctest-modules', '--ignore=mutants', '--random-order', '--strict-config', '--strict-markers', '-x', '-q', '--import-mode=append']

I first had to modify the pytest.ini to include --ignore mutants to get pytest itself happy, but I still can't get mutmut to play ball.

[pytest]
addopts = --doctest-glob="*.md" --doctest-modules --ignore=mutants --random-order --strict-config --strict-markers
empty_parameter_set_mark = xfail
xfail_strict=true

Any suggestions greatly received.

Thanks!

boxed commented 1 week ago

Hmm.. I wonder what goes on here. Could you give me the full log? Is this crash from the stats phase, clean tests phase...?

Can you run python -m pytest inside the mutants folder?

adam-moss commented 6 days ago

Thanks for the replies.

In terms of command I'm doing poetry run mutmut run and the log I'm getting is as follows:

~/Projects/**redact** (test/mutmut *$%|u=) % poetry run mutmut run
generating mutants
    done in 12066ms
⠦ running stats
Traceback (most recent call last):
  File "/Users/adam-moss/Projects/**redact**/.venv/bin/mutmut", line 8, in <module>
    sys.exit(cli())
             ~~~^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 1170, in run
    collect_or_load_stats(runner)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 1016, in collect_or_load_stats
    run_stats_collection(runner)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 994, in run_stats_collection
    collect_stats_exit_code = runner.run_stats(tests=tests)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 711, in run_stats
    return int(self.execute_pytest(['-x', '-q', '--import-mode=append'] + list(tests), plugins=[stats_collector]))
               ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 694, in execute_pytest
    raise BadTestExecutionCommandsException(params)
mutmut.__main__.BadTestExecutionCommandsException: ['--doctest-glob=*.md', '--doctest-modules', '--ignore=mutants', '--random-order', '--strict-config', '--strict-markers', '-x', '-q', '--import-mode=append']

Thanks!

boxed commented 6 days ago

What happens when you run poetry run pytest --doctest-glob=*.md --doctest-modules --ignore=mutants --random-order --strict-config --strict-markers -x -q --import-mode=append ?

adam-moss commented 6 days ago

In the root of the project dir it fails with

ImportError while loading conftest '/Users/adam.moss/Projects/**redact/tests/conftest.py'.
ModuleNotFoundError: No module named 'tests.conftest'

If I remove the --import-mode=append it works as expect, tests run and pass.

If I run when in the mutants directory I get the same error with --import-mode=append as above, without it pytest fails to run with:

______________ ERROR collecting mutants/src/**redact**/__about__.py _______________
import file mismatch:
imported module '**redact**.__about__' has this __file__ attribute:
  /Users/adam.moss/Projects/**redact**/src/**redact**/__about__.py
which is not the same as the test file we want to collect:
  /Users/adam.moss/Projects/**redact**/mutants/src/**redact**/__about__.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
=========================== short test summary info ============================
ERROR src/**redact**/__about__.py
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 error in 0.14s

Removing all *.pyc files doesn't make a difference.

boxed commented 6 days ago

Could you try again with the latest code that is on main now? I have made some improvements to this.

adam-moss commented 6 days ago

Using the latest on main if I run poetry run mutmut run from the project root I get

% poetry run mutmut run
⠹ Generating mutants
    done in 529ms
⠏ Running stats     
Traceback (most recent call last):
  File "/Users/adam-moss/Projects/**redact**/.venv/bin/mutmut", line 8, in <module>
    sys.exit(cli())
             ~~~^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 1225, in run
    collect_or_load_stats(runner)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 1055, in collect_or_load_stats
    run_stats_collection(runner)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 1033, in run_stats_collection
    collect_stats_exit_code = runner.run_stats(tests=tests)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 720, in run_stats
    return int(self.execute_pytest(['-x', '-q', '--import-mode=append'] + list(tests), plugins=[stats_collector]))
               ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 701, in execute_pytest
    raise BadTestExecutionCommandsException(params)
mutmut.__main__.BadTestExecutionCommandsException: ['--doctest-glob=*.md', '--doctest-modules', '--ignore=mutants', '--random-order', '--strict-config', '--strict-markers', '-x', '-q', '--import-mode=append', '--rootdir=.']

If I run from within the mutants directory I get:

% cd mutants 
% poetry run mutmut run
⠹ Generating mutants
Traceback (most recent call last):
  File "/Users/adam-moss/Projects/**redact**/.venv/bin/mutmut", line 8, in <module>
    sys.exit(cli())
             ~~~^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 1203, in run
    create_mutants()
    ~~~~~~~~~~~~~~^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 215, in create_mutants
    create_mutants_for_file(path, output_path)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 251, in create_mutants_for_file
    mutant_names, hash_by_function_name = write_all_mutants_to_file(out=out, source=source, filename=filename)
                                          ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 295, in write_all_mutants_to_file
    for type_, x, name_and_hash, mutant_name in yield_mutants_for_module(ast, no_mutate_lines):
                                                ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 571, in yield_mutants_for_module
    yield from yield_mutants_for_class(child_node, no_mutate_lines=no_mutate_lines)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 527, in yield_mutants_for_class
    yield from yield_mutants_for_class_body(child_node, no_mutate_lines=no_mutate_lines)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 538, in yield_mutants_for_class_body
    yield from yield_mutants_for_function(child_node, class_name=class_name, no_mutate_lines=no_mutate_lines)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 493, in yield_mutants_for_function
    with rename_function_node(node, suffix='orig', class_name=class_name):
         ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam-moss/.homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/contextlib.py", line 141, in __enter__
    return next(self.gen)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 342, in rename_function_node
    mangled_name = mangle_function_name(name=orig_name, class_name=class_name)
  File "/Users/adam-moss/Projects/**redact**/.venv/lib/python3.13/site-packages/mutmut/__main__.py", line 781, in mangle_function_name
    assert CLASS_NAME_SEPARATOR not in name
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

As before poetry run pytest works from the project root but fails within the mutants folder.

boxed commented 6 days ago

Maybe you could try to reproduce this on a smaller repo that you can share? Doing it back and forth like this isn't going so well...

adam-moss commented 3 days ago

Initial repo https://github.com/adam-moss/mutmut-issue-340