-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Show subprocess stdout and stderr on pytest failure #29890
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
Show subprocess stdout and stderr on pytest failure #29890
Conversation
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
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.
Thanks for the PR.
lib/matplotlib/testing/__init__.py
Outdated
@@ -105,6 +105,9 @@ def subprocess_run_for_testing(command, env=None, timeout=60, stdout=None, | |||
import pytest | |||
pytest.xfail("Fork failure") | |||
raise | |||
except subprocess.CalledProcessError as e: | |||
import pytest | |||
pytest.xfail(f"Subprocess failed with exit code {e.returncode}:\n{e.stdout}\n{e.stderr}") |
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.
This should be a plain fail not an xfail, also made it a bit more verbose to make stdout and stderr output easier to read:
pytest.xfail(f"Subprocess failed with exit code {e.returncode}:\n{e.stdout}\n{e.stderr}") | |
pytest.fail( | |
f"Subprocess failed with exit code {e.returncode}:\n\n" | |
f"STDOUT:\n{e.stdout}\n\nSTDERR:\n{e.stderr}") |
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.
Thanks! I agree I like yours better. Just made the change.
In fact, it's a little more complicated than that. We have use cases where we expect the subprocess to fail (or more generally are ok with that), e.g. So we cannot unconditionally
|
Looks like some tests catch the For example, b43b568 is a change that could be made to make sure that the actual |
I like this approach for keeping this PR small and in case tests actually need to catch a subprocess error. The tests I have seen can be refactored to set this |
That change is invalid though; as the comment says, the test is specifically ignoring all other failures. |
@QuLogic Yeah I realized that after it failed again, sorry about that. So the errors definitely need to propagate through I agree, just wanted to see if it was easy to add the outputs to stdout and stderr from the subprocess back into the main process to make errors more visible. |
This may work better now. It should show the subprocess' If you think this change is unnecessary feel free to close the PR. |
@thomashopkins32 Can you please squash this to one commit? |
Confirmed that this comes out nicely in the logs. |
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.
modulo squashing.
For full disclosure, Tom is a co-worker so scale my approval by whatever conflict of interest factor you want.
9165149
to
126507f
Compare
This is a low-risk change, so I'm happy to merge with any 1.x approval factor. Thanks @ Tom x 2 (to stay in the math terminology 😆) |
PR summary
Displays the captured
stdout
andstderr
when a pytest test that uses the subprocess helper exits in failure.PR checklist