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

Always show stdout and stderr? #156

Closed
hblok opened this issue Sep 2, 2017 · 3 comments
Closed

Always show stdout and stderr? #156

hblok opened this issue Sep 2, 2017 · 3 comments

Comments

@hblok
Copy link

hblok commented Sep 2, 2017

I always want to see the output to stdout and stderr in the console, as well as have both recorded to the XML file, also when a test passes.

However, regardless of what settings I use for buffer, verbosity, stdout and stderr only go to the xml report file if the test passes. If it fails, I see both in the console and the file. This can be isolated to the use of the XMLTestRunner. If that line is commented out in the example below, buffer works as documented and expected, and stdout / stderr are shown in the console.

I can consistently reproduce this on Python 2.7 and 3.4.

Here is the example I'm running. (The print(file=sys.stderr) works in Python 3 only).

class TestXmlRunner(unittest.TestCase):

  def test_hello(self):
    print('hello')
    print('hello stderr', file=sys.stderr)
    self.assertTrue(True)

if __name__ == '__main__':
    unittest.main(
        testRunner=xmlrunner.XMLTestRunner(output='/tmp/test-reports',
                                           verbosity=2, buffer=False),
        verbosity=2, buffer=False)

Help, comments, fixes welcome. Happy to contribute with a fix, if I know what to fix.

Regards,
hblok

@McMagnus
Copy link

McMagnus commented Nov 8, 2017

Had the same problem, perhaps not exactly what you're looking for, but I used this in the main function before starting the runner:

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

I then output all output using a logger, not print.

@hblok
Copy link
Author

hblok commented Dec 20, 2017

I found yet another workaround: Use the static original sys._ _ stdout _ _ instead. It will not be high-jacked by the testrunner. E.g.

sys.__stdout__.write("hello")

print("hello", file=sys.__stdout__)

@ikedam
Copy link
Contributor

ikedam commented May 13, 2018

I believe #166 resolves this issue.
It's merged but not released yet.

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

4 participants