[py-dev] Adding a funcarg to pytest_capturelog plugin
flub at devork.be
Mon Nov 29 23:38:29 CET 2010
Your capturelog plugin for py.test is very useful, thanks for writing
it! But recently I've had the need to be able to modify the recorded
loglevel inside the test (or during test setup) mostly to temporarily
silence the logging. For this I added a funcarg named "capturelog"
which exposes the loghandler (wrapped so it can be used as a context
manager too) which seems like a fairly nice way to work. The only
ugly part of this is that I had to store the loghandler instance on
the function instance as well instead of just on the item.
The second thing I wanted to do was to be able to assert on the
contents of log messages, specifically I wanted to ensure there where
no critical messages logged. Having the above funcarg already it
seemed most logical to just add this to the same loghandler already
used by overwriting the .emit() method to store the raw LogRecord
instances. I guess you could argue as to weather the list of
LogRecord instances or the entire py.io.TextIO version of log should
be made available, but I preferred the former.
I've cloned your repository at
http://bitbucket.org/flub/pytest-capturelog/ to add this
functionality, the changes should be pretty simple and obvious. I
think it could be useful if you could merge a version of this. Let me
know if you have remarks or would like to see things slightly
Lastly, while talking on #pylib (IRC) to Holger he mentioned that he
wondered if it would be worth to include the capturelog extension as a
default plugin in py.test since it is to cooperate with a stdlib
module. So if you also think this is interesting you might like to
discuss this with him.
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org
More information about the Pytest-dev