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

mutmut and @property #259

Open
ljd42 opened this issue Oct 3, 2022 · 4 comments
Open

mutmut and @property #259

ljd42 opened this issue Oct 3, 2022 · 4 comments

Comments

@ljd42
Copy link

ljd42 commented Oct 3, 2022

Hi there,

During my last Python class, one participant discovered an interesting case with @property, which I reproduced and simplified below.

"""demo mutmut issue with @property"""

class A:
    def __init__(self, value=0):
        self.x = value

    @property
    def x(self):
        return self._x

    @x.setter
    def x(self, value):
        if isinstance(value, (int,float)):
            self._x = value
        else:
            raise TypeError

mutmut is reporting one survivor:

  • the mutation that removes the @property decoration

Now I am wondering. Applying the mutation causes a Syntax Error, whence the test suite does not run at all.

Does that count as survived? Or are we supposed in this case to suppress the mutation with a #pragma?

Thanks in advance,
Loic.

@boxed
Copy link
Owner

boxed commented Oct 3, 2022

If it's a syntaxerror it should have failed the test run, and that should have caused the mutation to be marked as killed.

@ljd42
Copy link
Author

ljd42 commented Oct 3, 2022

Hi Anders,

Unfortunately, it doesn't :( One mutant survives (3), diff below:

PYTHONPATH='./src' mutmut show 3
--- ./src/issue.py
+++ ./src/issue.py
@@ -4,7 +4,6 @@
     def __init__(self, value=0):
         self.x = value
 
-    @property
     def x(self):
         return self._x

If I apply the mutation and re-run the test suite manually:

PYTHONPATH='./src/' pytest
============================= test session starts ==============================
platform linux -- Python 3.10.7, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/loic/oss/issue_mutmut
plugins: cov-3.0.0
collected 0 items / 1 error                                                    

==================================== ERRORS ====================================
_____________________ ERROR collecting test/test_issue.py ______________________
test/test_issue.py:2: in <module>
    from issue import A
src/issue.py:3: in <module>
    class A:
src/issue.py:10: in A
    @x.setter
E   AttributeError: 'function' object has no attribute 'setter'
=========================== short test summary info ============================
ERROR test/test_issue.py - AttributeError: 'function' object has no attribute...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.15s ===============================

Happy to provide further information later on if required.

@ljd42
Copy link
Author

ljd42 commented Oct 3, 2022

Just had a quick look at the code... I might have a clue about the issue.
In __init.py:tests_passed() returns true if returncode != 1.

Because the test fails due to an uncaught exception, in this particular case the return code will be 2 (On Unixoide at least. TBD on Windows).

@ljd42
Copy link
Author

ljd42 commented Oct 3, 2022

Unfortunately, I couldn't enter pdb by adding breakpoint() before the above line. So, I switched back to a simple print statement.

Hypothesis confirmed:

2. Checking mutants
⠸ 0/5  🎉 0  ⏰ 0  🤔 0  🙁 0  🔇 0*** returncode =1
⠸ 1/5  🎉 1  ⏰ 0  🤔 0  🙁 0  🔇 0*** returncode =1
⠴ 2/5  🎉 2  ⏰ 0  🤔 0  🙁 0  🔇 0*** returncode =2
⠸ 3/5  🎉 2  ⏰ 0  🤔 0  🙁 1  🔇 0*** returncode =1
⠇ 4/5  🎉 3  ⏰ 0  🤔 0  🙁 1  🔇 0*** returncode =1
⠏ 5/5  🎉 4  ⏰ 0  🤔 0  🙁 1  🔇 0

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