Is there some simple way of capturing and making assertions about logged messages with nose?
For example, I’d like to be able to do something like:
cook_eggs()
assert_logged("eggs are ready!")
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can create a custom handler which can check for the message being sent through logging. The BufferingHandler is a perfect match for this job.
You might also want to attach in your test the handler to any logger you are using in your code, such as
logging.getLogger('foo').addHandler(...). You could eventually attach the handler in thesetUpandtearDownmethods of your test case.