[Biopython-dev] [Bug 2754] Bio.PDB: Parse warnings should print to stderr, not stdout

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Thu Apr 23 15:43:04 UTC 2009


http://bugzilla.open-bio.org/show_bug.cgi?id=2754





------- Comment #13 from biopython-bugzilla at maubp.freeserve.co.uk  2009-04-23 11:43 EST -------
In comment #3 Bruce wrote:
> 
> I believe that we should be using the using Python warnings module for these
> types of messages:
> http://docs.python.org/library/warnings.html 
> 
> This permits the user to have a greater control over the output and also
> allows redirecting the output as required. In the Bio directory, there are
> currently 36 and 25 uses of stderr and stdout, respectively.
> 
> In terms of the patch, my limited understanding is that local import sys will
> override any global redirection of the output which in my opinion is a bad
> idea.

Good points, and yes, using the warnings module here (and probably elsewhere in
Biopython) makes sense.

Eric wrote in comment #9:
> Yes, something must be done with test_PDB.py, because I don't think
> warnings.warn can be made to play nice with that print-and-compare test
> -- or any print-and-compare, since the warning messages contain extra
> environment-specific information.

I was able to solve this with the following trick:

import warnings
def send_warnings_to_stdout(message, category, filename, lineno, file=None):
    print message
warnings.showwarning = send_warnings_to_stdout

This now prints *just* the message text without the stack trace information
etc.  This also means it looks like any other output from the print-and-compare
test, to test_PDB.py required only a trivial change.

Note that I haven't taken Eric's patches/branch as is - for one thing I wanted
to use the same import style as elsewhere in Biopython:

i.e.
import warnings
warnings.warn("Message")

rather than:

from warnings import warn
warn("Message")

However, I think we can now close Bug 2754.  Eric -  please try the latest code
from CVS (or the mirror on github).

Also, could you also open separate bug(s) for the other issues, such as your
new unittest based version of test_PDB.py?

Thanks,

Peter


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list