How to suppress exception printing to console?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu May 31 09:31:53 EDT 2012


On 2012年5月31日 15:57:08 +0800, Qi wrote:
> Hi guys,
>> I have an application that embedding Python into C++. When any exception
> occurred in C++ code, PyErr_SetString will be called to propagate the
> exception to Python.
>> The problem is, some unit tests trigger exception on intention. 

I'm sorry, I don't understand what you mean by "on intention".
> So it's
> OK to have the exceptions. But Python will still print the exception to
> console, polluting the unit test output.

Are you using the Python unittest module, or C++ unit tests?
Python's unittest catches and suppresses exceptions, so it should not be 
printing exceptions except as part of the normal unittest output.
 
> My question is, is there any way to disable exception reporting to
> console from either C++ or Python code?

If your unit tests are raising exceptions, your tests are broken. They 
should either raise expected exceptions, in which case the exception is a 
passing test, or they are failing tests, or they are bugs in your test 
code. Fix the failing tests and the bugs in the test code, don't hide 
them.
-- 
Steven


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /