Skip to content

bpo-34945: Buffer output in test suite only when creating junit file #10204

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

Merged
merged 3 commits into from
Oct 29, 2018

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Oct 28, 2018

After commit d0f49d2, the output of the
test suite is always buffered as the test output needs to be included in
the JUnit file in same cases (as when a test fails). This has the
consequence that printing or using debuggers (like pdb) in the test
suite does not result in a good user experience anymore.

This commit modifies the test suite runner so it only captures the test
output when the JUnit file is requested to fix the regression so prints
and debuggers are usable again.

CC: @matrixise

https://bugs.python.org/issue34945

ET.SubElement(e, 'system-out').text = stdout
stderr = self._stderr_buffer.getvalue().rstrip()
ET.SubElement(e, 'system-err').text = stderr
if self._stderr_buffer:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stdout?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups! I forgot to add that file when pushing the latest fix

After commit d0f49d2, the output of the
test suite is always buffered as the test output needs to be included in
the JUnit file in same cases (as when a test fails). This has the
consequence that printing or using debuggers (like pdb) in the test
suite does not result in a good user experience anymore.

This commit modifies the test suite runner so it only captures the test
output when the JUnit file is requested to fix the regression so prints
and debuggers are usable again.
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work for me: I don't see my print(). It works before the JUnit change.

vstinner@apu$ ./python -m test test_os
Run tests sequentially
0:00:00 load avg: 0.34 [1/1] test_os
git dif
== Tests result: SUCCESS ==

1 test OK.

Total duration: 1 sec 436 ms
Tests result: SUCCESS
vstinner@apu$ git diff
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 3f6e48f0c8..716b079a21 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -99,6 +99,7 @@ class FileTests(unittest.TestCase):
 
     def test_access(self):
         f = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
+        print("test_access")
         os.close(f)
         self.assertTrue(os.access(support.TESTFN, os.W_OK))

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@pablogsal
Copy link
Member Author

@vstinner Can your run it in verbose mode?

./python -m test test_os -v

@pablogsal
Copy link
Member Author

This is because the JUnit change made this choice:

return QuietRegressionTestRunner

@vstinner
Copy link
Member

@vstinner Can your run it in verbose mode?

I would like to get back the old behavior: see my print() without -v.
https://bugs.python.org/issue34945#msg327462

The commit d0f49d2 changed the behavior and it wasn't the intent of Steve Dower.
https://bugs.python.org/issue34945#msg327658

@pablogsal
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@zooba, @vstinner: please review the changes made to this pull request.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The functional test now works as expected: adding print("XXX") now displays XXX in stdout ;-)

Just a minor suggestion.

ET.SubElement(e, 'system-out').text = stdout
stderr = self._stderr_buffer.getvalue().rstrip()
ET.SubElement(e, 'system-err').text = stderr
if self._stdout_buffer:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use "is not None"?

@pablogsal pablogsal merged commit 0227748 into python:master Oct 29, 2018
@pablogsal pablogsal deleted the bpo34945 branch October 29, 2018 20:09
@vstinner
Copy link
Member

Since JUnit has been added to other branches, this change should be ported to other branches, no?

@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 29, 2018
…ythonGH-10204)

After commit d0f49d2, the output of the
test suite is always buffered as the test output needs to be included in
the JUnit file in same cases (as when a test fails). This has the
consequence that printing or using debuggers (like pdb) in the test
suite does not result in a good user experience anymore.

This commit modifies the test suite runner so it only captures the test
output when the JUnit file is requested to fix the regression so prints
and debuggers are usable again.
(cherry picked from commit 0227748)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
@bedevere-bot
Copy link

GH-10227 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 29, 2018
…ythonGH-10204)

After commit d0f49d2, the output of the
test suite is always buffered as the test output needs to be included in
the JUnit file in same cases (as when a test fails). This has the
consequence that printing or using debuggers (like pdb) in the test
suite does not result in a good user experience anymore.

This commit modifies the test suite runner so it only captures the test
output when the JUnit file is requested to fix the regression so prints
and debuggers are usable again.
(cherry picked from commit 0227748)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
@bedevere-bot
Copy link

GH-10228 is a backport of this pull request to the 3.6 branch.

miss-islington added a commit that referenced this pull request Oct 29, 2018
…H-10204)

After commit d0f49d2, the output of the
test suite is always buffered as the test output needs to be included in
the JUnit file in same cases (as when a test fails). This has the
consequence that printing or using debuggers (like pdb) in the test
suite does not result in a good user experience anymore.

This commit modifies the test suite runner so it only captures the test
output when the JUnit file is requested to fix the regression so prints
and debuggers are usable again.
(cherry picked from commit 0227748)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
miss-islington added a commit that referenced this pull request Oct 29, 2018
…H-10204)

After commit d0f49d2, the output of the
test suite is always buffered as the test output needs to be included in
the JUnit file in same cases (as when a test fails). This has the
consequence that printing or using debuggers (like pdb) in the test
suite does not result in a good user experience anymore.

This commit modifies the test suite runner so it only captures the test
output when the JUnit file is requested to fix the regression so prints
and debuggers are usable again.
(cherry picked from commit 0227748)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants