Inspect captured stderr in Python unit tests?

28 views
Skip to first unread message

cau...@gmail.com

unread,
Nov 9, 2017, 1:53:44 PM11/9/17
to grpc.io
Hi,

I have unit tests where I expect failures in the certificate verification inside the C core, e.g.,:

with self.assertRaises(...):
    # do something that causes C core to log to stderr
    pass

# I'd like to check the specific error messages, e.g.:
# assert 'some specific error message' in stderr
 

Is it at all possible to inspect the stderr in order to check that specific error messages are logged?
I see `src/python/grpcio_tests/tests/_runner.py` does the stdout/stderr capture, so I'm trying to look there, but any guidance is appreciated! e.g., "it's possible: look here," or "it will require a major change and/or won't be accepted" :)

Thanks!

Nathaniel Manista

unread,
Nov 9, 2017, 6:36:03 PM11/9/17
to Giang Nguyen, grpc.io
On Thu, Nov 9, 2017 at 10:53 AM, <cau...@gmail.com> wrote:
I have unit tests where I expect failures in the certificate verification inside the C core, e.g.,:

with self.assertRaises(...):
    # do something that causes C core to log to stderr
    pass

# I'd like to check the specific error messages, e.g.:
# assert 'some specific error message' in stderr

Is it at all possible to inspect the stderr in order to check that specific error messages are logged?

I'm not aware of any way to do this from within the same process as the system under test. It should be relatively easy to do if one's test exercises the system under test in a subprocess.

I see `src/python/grpcio_tests/tests/_runner.py` does the stdout/stderr capture, so I'm trying to look there, but any guidance is appreciated! e.g., "it's possible: look here," or "it will require a major change and/or won't be accepted" :)

We'd likely consider it philosophically unpalatable - the specific text of an error message should be prose addressed to a developer and not considered part of the supported API of a system. We would not like it to be the case that correcting a typo in a plain prose error message requires an update to our tests.
-N
Reply all
Reply to author
Forward
0 new messages