I have developed an application in Python and am using the Cement CLI library. I am using py.test
with the CementTestCase
. I can capture the output from stdout
in the test cases without a problem, using something like this:
with EZOTestApp(argv=['view', 'deploys']) as app:
old_stdout = sys.stdout
app.ezo = EZO(app.config["ezo"])
result = StringIO()
sys.stdout = result
app.run()
output = sys.stdout.getvalue()
sys.stdout = old_stdout
assert 'deploy' in output
However, in attempting to trap the stderr
output from the Cement
logging extension using the same mechanism captures nothing (re: replacing 'stdout' with 'stderr' in the above code). I saw a method for iterating through the standard Python logging handlers for finding the output, and I suspect something similar would be used the Cement
logging extension to capture stderr
, but I'm having trouble figuring it out. Anyone have any insight?