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

Fails to skip lines when context.skip set True in pre_mutation #321

Closed
johnesher opened this issue May 25, 2024 · 4 comments
Closed

Fails to skip lines when context.skip set True in pre_mutation #321

johnesher opened this issue May 25, 2024 · 4 comments

Comments

@johnesher
Copy link

This is my pre_mutation function in mutmut_config.py

def pre_mutation(context):
    line = context.current_source_line.strip()
    print('testing', line)
    if line.startswith('log'):
        print('skipping', line)
        context.skip = True
    if line.startswith('print'):
        print('skipping', line)
        context.skip = True

I can see it is being executed from the prints but it does not stop the mutations as shown by the snippet below

Mutant 29

--- <path hidden>/handlers.py
+++ <path hidden>/handlers.py
@@ -12,7 +12,7 @@
 #     from <hidden>
 
 
-logger = logging.getLogger(__name__)
+logger = None
 logger.setLevel(logging.DEBUG)
  

Mutant 30

--- <path hidden>/handlers.py
+++ <path hidden>/handlers.py
@@ -19,7 +19,7 @@
 def handle_event(event: events.NormalEvent) -> None:
     """TODO docstring"""
     # tick 
-    print(f"### handling {event}")
+    print(f"XX### handling {event}XX")
     logger.info("handling %s", event)
     # whatever 

There is no setup/config file and I am running mutmut like this

mutmut run --disable-mutation-types=string,number

I would expect the string in the print above not to be mutated.

Version is mutmut version 2.5.0 and running with python 3.10 in a venv on Ubuntu 22.04

@boxed
Copy link
Owner

boxed commented May 25, 2024

The output you showed looks like the mutmut show output. That just shows that mutmut has enumerated the mutant, not that it has tested that mutant.

@johnesher
Copy link
Author

Thanks that helps me to understand. I have quite a lot of items skipped at the moment and they make it hard to see the real mutants that need to be addressed in the report. Is there an option to omit skipped mutants from the report?

It also seems to me that the behaviour of --disable-mutation-types is unclear. Adding it halved the number of mutants, but some strings still survived as in this one below

Survived mutation testing. These mutants show holes in your test suite.
Mutant 126

--- src/example_client.py
+++ src/example_client.py
@@ -30,7 +30,7 @@
 
     def doing_something_that_sends_an_event(self):
         # return for test purposes
-        return self.send_event("it happened")
+        return self.send_event("XXit happenedXX")

@boxed
Copy link
Owner

boxed commented May 26, 2024

And it's not just that that mutant was checked when you didn't have that conf? The cache will remember mutants...

@boxed
Copy link
Owner

boxed commented Oct 20, 2024

I just released mutmut 3, which is a big rewrite. mutmut_config is not a thing in mutmut 3 (at least not yet), so this issue no longer applies.

@boxed boxed closed this as completed Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants