-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-25588: Fix regrtest when run inside IDLE #3962
Conversation
When regrtest in run inside IDLE, sys.stdout and sys.stderr are not TextIOWrapper objects and have no file descriptor associated: sys.stderr.fileno() raises io.UnsupportedOperation. Disable faulthandler and don't replace sys.stdout in that case.
I chose to not add a NEWS entry since running the Python test suite in IDLE causes many tests to fail. I don't think that we should promote running tests in IDLE. |
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.
LGTM even if it doesn't fix all tests.
Lib/test/libregrtest/setup.py
Outdated
except io.UnsupportedOperation: | ||
# On IDLE, sys.stdout has no file descriptor and is not a TextIOWrapper | ||
# object. Leaving sys.stdout unchanged. | ||
return |
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.
I'm wondering if we could use codecs.StreamRecoder
here. But this looks like a more complex issue.
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.
I expect that the IDLE shell handles correctly Unicode. replace_stdout() was written for terminals using ASCII/strict for stdout.
Lib/test/libregrtest/setup.py
Outdated
faulthandler.register(signum, chain=True) | ||
try: | ||
stderr_fd = sys.stderr.fileno() | ||
except io.UnsupportedOperation: |
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.
Maybe catch ValueError? This would cover the case of closed files too. And if support the case sys.stderr is None
we should catch AttributeError.
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.
ValueError: ok, I made the change. It avoids "import io", so I like it :-) Even if I'm not sure that we are supposed to support running tests with closed stderr...
AtttributeError: I'm not sure that it makes sense to run the test suite if there is no sys.stderr. Where are you supposed to write the output if there is not stdout nor stderr?
if hasattr(signal, 'SIGUSR1'): | ||
signals.append(signal.SIGUSR1) | ||
for signum in signals: | ||
faulthandler.register(signum, chain=True, file=stderr_fd) |
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.
Do the faulthandler functions absolutely need an fd int rather than the existing output object?
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.
faulthandler really needs a FD internally. The API accepts a file and calls .fileno() for you. Since we already know the FD, I prefer to directly pass the FD.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Lib/test/libregrtest/setup.py
Outdated
# | ||
# Catch ValueError to catch io.UnsupportedOperation on TextIOBase | ||
# and ValueError on a closed stream. | ||
stderr_fd = None |
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.
Replace line with
try:
stderr_fd = sys.__stderr__.fileno()
except ValueError:
stderr_fd = None
If IDLE is started from a command line or python (by import idlelib.idle), the backup call returns 2.
sys.stderr
<_io.TextIOWrapper name='' mode='w' encoding='utf-8'>
sys.stderr.fileno()
2
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.
done
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.
see previous comment
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
Thanks for making the requested changes! @serhiy-storchaka, @terryjreedy: please review the changes made to this pull request. |
Lib/test/libregrtest/setup.py
Outdated
try: | ||
stderr_fd = sys.__stderr__.fileno() | ||
except (ValueError, AttributeError): | ||
# In IDLE, sys.stderr.fileno() raises io.UnsupportedOperation: the |
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.
If you use sys.__stderr__.fileno()
this comment looks outdated.
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.
Right, removed.
Apveyor failure looks random and unrelated to this patch. Tests pass on my machine with a fresh build.
|
Thanks @Haypo for the PR 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6. |
GH-3987 is a backport of this pull request to the 3.6 branch. |
When regrtest in run inside IDLE, sys.stdout and sys.stderr are not TextIOWrapper objects and have no file descriptor associated: sys.stderr.fileno() raises io.UnsupportedOperation. Disable faulthandler and don't replace sys.stdout in that case. (cherry picked from commit ccef823)
"ERROR: setUpClass (test.test_nntplib.NetworkedNNTP_SSLTests)" That's an old but unfixed bug: https://bugs.python.org/issue30188 |
Sorry, @Haypo, I could not cleanly backport this to |
faulthandler doesn't exist in Python 2.7, not replace_stdout(). I tested: "import test.autotest" works in Python 2.7. |
When regrtest in run inside IDLE, sys.stdout and sys.stderr are not TextIOWrapper objects and have no file descriptor associated: sys.stderr.fileno() raises io.UnsupportedOperation. Disable faulthandler and don't replace sys.stdout in that case. (cherry picked from commit ccef823)
Thanks @Haypo! |
When regrtest in run inside IDLE, sys.stdout and sys.stderr are not
TextIOWrapper objects and have no file descriptor associated:
sys.stderr.fileno() raises io.UnsupportedOperation.
Disable faulthandler and don't replace sys.stdout in that case.
https://bugs.python.org/issue25588