summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/tests/support.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-06-02 12:53:59 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-06-02 12:53:59 (GMT)
commit78af7d8392b5671f6877b259df34c36b884dc103 (patch)
treed5ff0e1fec689fb7981062dbbafddea48cb0b745 /Lib/packaging/tests/support.py
parent5da37be7f25f07a48229dd1d409447c3ffbf3952 (diff)
downloadcpython-78af7d8392b5671f6877b259df34c36b884dc103.zip
cpython-78af7d8392b5671f6877b259df34c36b884dc103.tar.gz
cpython-78af7d8392b5671f6877b259df34c36b884dc103.tar.bz2
Make packaging.tests.support.LoggingCatcher.get_logs flush the log handler.
This removes the need to call flush manually in each test, except when testing code that creates warning without checking them.
Diffstat (limited to 'Lib/packaging/tests/support.py')
-rw-r--r--Lib/packaging/tests/support.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/packaging/tests/support.py b/Lib/packaging/tests/support.py
index 66b5583..ae65a1d 100644
--- a/Lib/packaging/tests/support.py
+++ b/Lib/packaging/tests/support.py
@@ -90,17 +90,23 @@ class LoggingCatcher:
def get_logs(self, *levels):
"""Return all log messages with level in *levels*.
- Without explicit levels given, returns all messages.
- *levels* defaults to all levels. For log calls with arguments (i.e.
- logger.info('bla bla %s', arg)), the messages
- Returns a list.
+ Without explicit levels given, returns all messages. *levels* defaults
+ to all levels. For log calls with arguments (i.e.
+ logger.info('bla bla %r', arg)), the messages will be formatted before
+ being returned (e.g. "bla bla 'thing'").
+
+ Returns a list. Automatically flushes the loghandler after being
+ called.
Example: self.get_logs(logging.WARN, logging.DEBUG).
"""
if not levels:
- return [log.getMessage() for log in self.loghandler.buffer]
- return [log.getMessage() for log in self.loghandler.buffer
- if log.levelno in levels]
+ messages = [log.getMessage() for log in self.loghandler.buffer]
+ else:
+ messages = [log.getMessage() for log in self.loghandler.buffer
+ if log.levelno in levels]
+ self.loghandler.flush()
+ return messages
class TempdirManager: