ted
ted

Reputation: 4975

Ignore stderr output for test result

I am trying to test a package with nose. During one of the tests I write to stderr, this causes the test to be reported as broken in Jenkins (I start the test using nose and generate the Junit .xml output to determine the success) Is it possible to ingore stderr or check it for certain values?

So fare my test looks roughly like this:

def testFunc() {
    f1()
    f2() }

And fails since I write to stderr from within, can I tell nose to ignore this or is the test missing something ( I expect it to fail only if an exception is generated)

edit: The assumption that the error output caused the failure was wrong. Between the 100s of lines of debbuging output was an exception. (for some reason jenkins showed the unformated(no line feeds) output first, then the exception trace, and after that the output was once more, with linefeeds. I just overlooked the exception)

Upvotes: 0

Views: 693

Answers (1)

Lenna
Lenna

Reputation: 1465

If you don't want to see the stderr, you could use logging tutorial.

Example:

import logging
logging.basicConfig(level=logging.ERROR)
# instead of sys.stderr.write():
logging.warning("This is a warning!")

In this instance, the warning is below the logging level threshold so it will not be printed to stderr. If you wanted to see the error but it doesn't have to be in real time, you could specify a log file (with the filename parameter to logging.basicConfig).

Upvotes: 3

Related Questions