-
Notifications
You must be signed in to change notification settings - Fork 59
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
pytest: handle non-zero exit code #313
pytest: handle non-zero exit code #313
Conversation
Without this PR I get invalid mutants, since the pytest failure is not detected. With this PR it looks like this then:
I think |
pytest supports these exit codes:
Related: pytest-dev/pytest#2950 |
Cosmic Ray is Python >= 3.4 so |
@@ -29,15 +27,31 @@ class PytestRunner(TestRunner): | |||
""" | |||
|
|||
def _run(self): | |||
try: | |||
from StringIO import StringIO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this. Just use from io import StringIO
args = self.test_args | ||
if args: | ||
args = args.split() | ||
else: | ||
args = [] | ||
with open(os.devnull, 'w') as devnull, redirect_stdout(devnull): | ||
pytest.main(args, plugins=[collector]) | ||
stdout = StringIO() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The StringIO
object is never close()
d – this isn't super important, but it's good practice rather than relying on the garbage collect to dispose of the buffer. We should probably manage so stdout
object using its context-manager interface, so:
with StringIO() as stdout:
Thanks for the review already. What do you think about having |
I'm not much in favour of centralising all the exception definitions. I'd rather have them organised with the code they are relevant to. A better place for |
@@ -29,16 +27,32 @@ class PytestRunner(TestRunner): | |||
""" | |||
|
|||
def _run(self): | |||
from io import StringIO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this import be at the top of the module? That would be more idiomatic, less surprising, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do it for now (but only later) - in the long run this should go/come with TestRunner
likely anyway.
All in all this looks like a good change. It's certainly more thoroughly thought-out than my initial implementation. I'm still going around in circles trying to decide if a special I'm happy to be convinced one way or the other. Perhaps I'm missing some important point here! |
I think the benefit from having |
Can you explain the test failure? (haven't investigated - is it because of incompetent vs. failed?!)
|
No explanation right now. I don't think it can be incompetent mutants; those count as killed for reporting purposes. What we have here is a very high survival rate, so somehow the test suites are passing. If I do the mutation run directly on my machine, everything works as it should (i.e. no survivors). However, if I run |
I like the |
35d27f0
to
d45aac7
Compare
I am seeing the same failure with |
The problem is in the report generator. It's not accounting for incompetent mutants, i.e. I think you can fix this properly by changing
or something equivalent. If you want to make this change as part of your PR, I'll be fine with that. Or if you'd prefer I can make a separate change and you can merge it in. In either case, it sounds like we need an automated test for this situation. |
re the test failure: the exit code is 2 since cosmic-ray/cosmic_ray/reporting.py Lines 39 to 47 in d45aac7
|
Created #325 for now, let's see if it is covered already. |
At least for the purposes of reporting, incompetent mutants are considered killed. The idea is that, since they couldn't even run, the test suite is not passing the mutants. This is as good as killed for the purposes of gauging test suite quality. |
@blueyed With the exception of the linting error on travis, do you consider this ready to merge? If so, I'll merge it in and fix the lint issue separately. I figure we can deal with the |
@abingham |
I propose we merge this as is and iterate more later. Clearly we're still in the learning phase here, and I think there's a lot to be gained by merging and using this. |
837ce24
to
8209be2
Compare
Ok, fixed the Please consider squash-merging it then. |
Oh, this is absurd! Now the build is failing just because pytest.org happens to be down right now. |
Can you restart it (just for postery)? https://travis-ci.org/sixty-north/cosmic-ray/jobs/308106781 |
For reference: pytest 3.3.0 uses exit code 1 now with |
Unfortunately, I think we can't re-run that since the ref has been removed. |
TODO:
CosmicRayException
base? Should there be aexceptions
module for this?io.StringIO
is used (without the compat). Should be done here then also I assume?